Source Code Cross Referenced for IoBuffer.java in  » Net » mina-2.0.0-M1 » org » apache » mina » common » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » mina 2.0.0 M1 » org.apache.mina.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one
0003:         *  or more contributor license agreements.  See the NOTICE file
0004:         *  distributed with this work for additional information
0005:         *  regarding copyright ownership.  The ASF licenses this file
0006:         *  to you under the Apache License, Version 2.0 (the
0007:         *  "License"); you may not use this file except in compliance
0008:         *  with the License.  You may obtain a copy of the License at
0009:         *
0010:         *    http://www.apache.org/licenses/LICENSE-2.0
0011:         *
0012:         *  Unless required by applicable law or agreed to in writing,
0013:         *  software distributed under the License is distributed on an
0014:         *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015:         *  KIND, either express or implied.  See the License for the
0016:         *  specific language governing permissions and limitations
0017:         *  under the License.
0018:         *
0019:         */
0020:        package org.apache.mina.common;
0021:
0022:        import java.io.IOException;
0023:        import java.io.InputStream;
0024:        import java.io.OutputStream;
0025:        import java.nio.BufferOverflowException;
0026:        import java.nio.ByteBuffer;
0027:        import java.nio.ByteOrder;
0028:        import java.nio.CharBuffer;
0029:        import java.nio.DoubleBuffer;
0030:        import java.nio.FloatBuffer;
0031:        import java.nio.IntBuffer;
0032:        import java.nio.LongBuffer;
0033:        import java.nio.ReadOnlyBufferException;
0034:        import java.nio.ShortBuffer;
0035:        import java.nio.charset.CharacterCodingException;
0036:        import java.nio.charset.CharsetDecoder;
0037:        import java.nio.charset.CharsetEncoder;
0038:        import java.util.EnumSet;
0039:        import java.util.HashSet;
0040:        import java.util.Set;
0041:
0042:        /**
0043:         * A byte buffer used by MINA applications.
0044:         * <p>
0045:         * This is a replacement for {@link ByteBuffer}. Please refer to
0046:         * {@link ByteBuffer} documentation for preliminary usage.  MINA does
0047:         * not use NIO {@link ByteBuffer} directly for two reasons:
0048:         * <ul>
0049:         * <li>It doesn't provide useful getters and putters such as
0050:         * <code>fill</code>, <code>get/putString</code>, and
0051:         * <code>get/putAsciiInt()</code> enough.</li>
0052:         * <li>It is difficult to write variable-length data due to its fixed
0053:         * capacity</li>
0054:         * </ul>
0055:         * </p>
0056:         *
0057:         * <h2>Allocation</h2>
0058:         * <p>
0059:         * You can allocate a new heap buffer.
0060:         * <pre>
0061:         * IoBuffer buf = IoBuffer.allocate(1024, false);
0062:         * </pre>
0063:         * you can also allocate a new direct buffer:
0064:         * <pre>
0065:         * IoBuffer buf = IoBuffer.allocate(1024, true);
0066:         * </pre>
0067:         * or you can set the default buffer type.
0068:         * <pre>
0069:         * // Allocate heap buffer by default.
0070:         * IoBuffer.setUseDirectBuffer(false);
0071:         * // A new heap buffer is returned.
0072:         * IoBuffer buf = IoBuffer.allocate(1024);
0073:         * </pre>
0074:         * </p>
0075:         *
0076:         * <h2>Wrapping existing NIO buffers and arrays</h2>
0077:         * <p>
0078:         * This class provides a few <tt>wrap(...)</tt> methods that wraps
0079:         * any NIO buffers and byte arrays.
0080:         *
0081:         * <h2>AutoExpand</h2>
0082:         * <p>
0083:         * Writing variable-length data using NIO <tt>ByteBuffers</tt> is not really
0084:         * easy, and it is because its size is fixed.  {@link IoBuffer} introduces 
0085:         * <tt>autoExpand</tt> property.  If <tt>autoExpand</tt> property is true, you
0086:         * never get {@link BufferOverflowException} or
0087:         * {@link IndexOutOfBoundsException} (except when index is negative).
0088:         * It automatically expands its capacity and limit value.  For example:
0089:         * <pre>
0090:         * String greeting = messageBundle.getMessage( "hello" );
0091:         * IoBuffer buf = IoBuffer.allocate( 16 );
0092:         * // Turn on autoExpand (it is off by default)
0093:         * buf.setAutoExpand( true );
0094:         * buf.putString( greeting, utf8encoder );
0095:         * </pre>
0096:         * The underlying {@link ByteBuffer} is reallocated by {@link IoBuffer} behind
0097:         * the scene if the encoded data is larger than 16 bytes in the example above.
0098:         * Its capacity will double, and its limit will increase to the last position
0099:         * the string is written.
0100:         * </p>
0101:         * 
0102:         * <h2>AutoShrink</h2>
0103:         * <p>
0104:         * You might also want to decrease the capacity of the buffer when most
0105:         * of the allocated memory area is not being used.  {@link IoBuffer} provides
0106:         * <tt>autoShrink</tt> property to take care of this issue.  If 
0107:         * <tt>autoShrink</tt> is turned on, {@link IoBuffer} halves the capacity
0108:         * of the buffer when {@link #compact()} is invoked and only 1/4 or less of
0109:         * the current capacity is being used.
0110:         * <p>
0111:         * You can also {@link #shrink()} method manually to shrink the capacity of
0112:         * the buffer.
0113:         * <p> 
0114:         * The underlying {@link ByteBuffer} is reallocated by {@link IoBuffer} behind
0115:         * the scene, and therefore {@link #buf()} will return a different
0116:         * {@link ByteBuffer} instance once capacity changes.  Please also note
0117:         * {@link #compact()} or {@link #shrink()} will not decrease the capacity if
0118:         * the new capacity is less than the {@link #minimumCapacity()} of the buffer.
0119:         *
0120:         * <h2>Derived Buffers</h2>
0121:         * <p>
0122:         * Derived buffers are the buffers which were created by
0123:         * {@link #duplicate()}, {@link #slice()}, or {@link #asReadOnlyBuffer()}.
0124:         * They are useful especially when you broadcast the same messages to
0125:         * multiple {@link IoSession}s.  Please note that the buffer derived from and
0126:         * its derived buffers are not both auto-expandable neither auto-shrinkable.
0127:         * Trying to call {@link #setAutoExpand(boolean)} or {@link #setAutoShrink(boolean)}
0128:         * with <tt>true</tt> parameter will raise an {@link IllegalStateException}.
0129:         * </p>
0130:         *
0131:         * <h2>Changing Buffer Allocation Policy</h2>
0132:         * <p>
0133:         * {@link IoBufferAllocator} interface lets you override the default buffer
0134:         * management behavior.  There are two allocators provided out-of-the-box:
0135:         * <ul>
0136:         * <li>{@link SimpleBufferAllocator} (default)</li>
0137:         * <li>{@link CachedBufferAllocator}</li>
0138:         * </ul>
0139:         * You can implement your own allocator and use it by calling
0140:         * {@link #setAllocator(IoBufferAllocator)}.
0141:         * </p>
0142:         *
0143:         * @author The Apache MINA Project (dev@mina.apache.org)
0144:         * @version $Rev: 602109 $, $Date: 2007-12-07 07:40:41 -0700 (Fri, 07 Dec 2007) $
0145:         */
0146:        public abstract class IoBuffer implements  Comparable<IoBuffer> {
0147:            private static IoBufferAllocator allocator = new SimpleBufferAllocator();
0148:
0149:            private static final IoBuffer EMPTY_DIRECT_BUFFER = allocator
0150:                    .allocate(0, true);
0151:
0152:            private static final IoBuffer EMPTY_HEAP_BUFFER = allocator
0153:                    .allocate(0, false);
0154:
0155:            private static boolean useDirectBuffer = false;
0156:
0157:            /**
0158:             * An immutable empty buffer.
0159:             */
0160:            public static final IoBuffer EMPTY_BUFFER = wrap(new byte[0]);
0161:
0162:            /**
0163:             * Returns the allocator used by existing and new buffers
0164:             */
0165:            public static IoBufferAllocator getAllocator() {
0166:                return allocator;
0167:            }
0168:
0169:            /**
0170:             * Sets the allocator used by existing and new buffers
0171:             */
0172:            public static void setAllocator(IoBufferAllocator newAllocator) {
0173:                if (newAllocator == null) {
0174:                    throw new NullPointerException("allocator");
0175:                }
0176:
0177:                IoBufferAllocator oldAllocator = allocator;
0178:
0179:                allocator = newAllocator;
0180:
0181:                if (null != oldAllocator) {
0182:                    oldAllocator.dispose();
0183:                }
0184:            }
0185:
0186:            /**
0187:             * Returns <tt>true</tt> if and only if a direct buffer is allocated
0188:             * by default when the type of the new buffer is not specified.  The
0189:             * default value is <tt>false</tt>.
0190:             */
0191:            public static boolean isUseDirectBuffer() {
0192:                return useDirectBuffer;
0193:            }
0194:
0195:            /**
0196:             * Sets if a direct buffer should be allocated by default when the
0197:             * type of the new buffer is not specified.  The default value is
0198:             * <tt>false</tt>.
0199:             */
0200:            public static void setUseDirectBuffer(boolean useDirectBuffer) {
0201:                IoBuffer.useDirectBuffer = useDirectBuffer;
0202:            }
0203:
0204:            /**
0205:             * Returns the direct or heap buffer which is capable to store the
0206:             * specified amount of bytes.
0207:             *
0208:             * @param capacity the capacity of the buffer
0209:             *
0210:             * @see #setUseDirectBuffer(boolean)
0211:             */
0212:            public static IoBuffer allocate(int capacity) {
0213:                return allocate(capacity, useDirectBuffer);
0214:            }
0215:
0216:            /**
0217:             * Returns the buffer which is capable of the specified size.
0218:             *
0219:             * @param capacity the capacity of the buffer
0220:             * @param direct   <tt>true</tt> to get a direct buffer,
0221:             *                 <tt>false</tt> to get a heap buffer.
0222:             */
0223:            public static IoBuffer allocate(int capacity, boolean direct) {
0224:                if (capacity == 0) {
0225:                    return direct ? EMPTY_DIRECT_BUFFER : EMPTY_HEAP_BUFFER;
0226:                }
0227:
0228:                if (capacity < 0) {
0229:                    throw new IllegalArgumentException("capacity: " + capacity);
0230:                }
0231:
0232:                return allocator.allocate(capacity, direct);
0233:            }
0234:
0235:            /**
0236:             * Wraps the specified NIO {@link ByteBuffer} into MINA buffer.
0237:             */
0238:            public static IoBuffer wrap(ByteBuffer nioBuffer) {
0239:                return allocator.wrap(nioBuffer);
0240:            }
0241:
0242:            /**
0243:             * Wraps the specified byte array into MINA heap buffer.
0244:             */
0245:            public static IoBuffer wrap(byte[] byteArray) {
0246:                return wrap(ByteBuffer.wrap(byteArray));
0247:            }
0248:
0249:            /**
0250:             * Wraps the specified byte array into MINA heap buffer.
0251:             */
0252:            public static IoBuffer wrap(byte[] byteArray, int offset, int length) {
0253:                return wrap(ByteBuffer.wrap(byteArray, offset, length));
0254:            }
0255:
0256:            /**
0257:             * Normalizes the specified capacity of the buffer to power of 2,
0258:             * which is often helpful for optimal memory usage and performance. 
0259:             * If it is greater than or equal to {@link Integer#MAX_VALUE}, it
0260:             * returns {@link Integer#MAX_VALUE}.  If it is zero, it returns zero.
0261:             */
0262:            protected static int normalizeCapacity(int requestedCapacity) {
0263:                switch (requestedCapacity) {
0264:                case 0:
0265:                case 1 << 0:
0266:                case 1 << 1:
0267:                case 1 << 2:
0268:                case 1 << 3:
0269:                case 1 << 4:
0270:                case 1 << 5:
0271:                case 1 << 6:
0272:                case 1 << 7:
0273:                case 1 << 8:
0274:                case 1 << 9:
0275:                case 1 << 10:
0276:                case 1 << 11:
0277:                case 1 << 12:
0278:                case 1 << 13:
0279:                case 1 << 14:
0280:                case 1 << 15:
0281:                case 1 << 16:
0282:                case 1 << 17:
0283:                case 1 << 18:
0284:                case 1 << 19:
0285:                case 1 << 21:
0286:                case 1 << 22:
0287:                case 1 << 23:
0288:                case 1 << 24:
0289:                case 1 << 25:
0290:                case 1 << 26:
0291:                case 1 << 27:
0292:                case 1 << 28:
0293:                case 1 << 29:
0294:                case 1 << 30:
0295:                case Integer.MAX_VALUE:
0296:                    return requestedCapacity;
0297:                }
0298:
0299:                int newCapacity = 1;
0300:                while (newCapacity < requestedCapacity) {
0301:                    newCapacity <<= 1;
0302:                    if (newCapacity < 0) {
0303:                        return Integer.MAX_VALUE;
0304:                    }
0305:                }
0306:                return newCapacity;
0307:            }
0308:
0309:            protected static final Set<String> primitiveTypeNames = new HashSet<String>();
0310:
0311:            static {
0312:                primitiveTypeNames.add("void");
0313:                primitiveTypeNames.add("boolean");
0314:                primitiveTypeNames.add("byte");
0315:                primitiveTypeNames.add("char");
0316:                primitiveTypeNames.add("short");
0317:                primitiveTypeNames.add("int");
0318:                primitiveTypeNames.add("long");
0319:                primitiveTypeNames.add("float");
0320:                primitiveTypeNames.add("double");
0321:            }
0322:
0323:            /**
0324:             * Creates a new instance.  This is an empty constructor.
0325:             */
0326:            protected IoBuffer() {
0327:            }
0328:
0329:            /**
0330:             * Declares this buffer and all its derived buffers are not used anymore
0331:             * so that it can be reused by some {@link IoBufferAllocator} implementations.
0332:             * It is not mandatory to call this method, but you might want to invoke this
0333:             * method for maximum performance. 
0334:             */
0335:            public abstract void free();
0336:
0337:            /**
0338:             * Returns the underlying NIO buffer instance.
0339:             */
0340:            public abstract ByteBuffer buf();
0341:
0342:            /**
0343:             * @see ByteBuffer#isDirect()
0344:             */
0345:            public abstract boolean isDirect();
0346:
0347:            /**
0348:             * returns <tt>true</tt> if and only if this buffer is derived from other buffer
0349:             * via {@link #duplicate()}, {@link #slice()} or {@link #asReadOnlyBuffer()}.
0350:             */
0351:            public abstract boolean isDerived();
0352:
0353:            /**
0354:             * @see ByteBuffer#isReadOnly()
0355:             */
0356:            public abstract boolean isReadOnly();
0357:
0358:            /**
0359:             * Returns the minimum capacity of this buffer which is used to determine
0360:             * the new capacity of the buffer shrunk by {@link #compact()} and
0361:             * {@link #shrink()} operation.  The default value is the initial capacity
0362:             * of the buffer.
0363:             */
0364:            public abstract int minimumCapacity();
0365:
0366:            /**
0367:             * Sets the minimum capacity of this buffer which is used to determine
0368:             * the new capacity of the buffer shrunk by {@link #compact()} and
0369:             * {@link #shrink()} operation.  The default value is the initial capacity
0370:             * of the buffer.
0371:             */
0372:            public abstract IoBuffer minimumCapacity(int minimumCapacity);
0373:
0374:            /**
0375:             * @see ByteBuffer#capacity()
0376:             */
0377:            public abstract int capacity();
0378:
0379:            /**
0380:             * Increases the capacity of this buffer.  If the new capacity is less than
0381:             * or equal to the current capacity, this method returns silently.  If the
0382:             * new capacity is greater than the current capacity, the buffer is
0383:             * reallocated while retaining the position, limit, mark and the content
0384:             * of the buffer.
0385:             */
0386:            public abstract IoBuffer capacity(int newCapacity);
0387:
0388:            /**
0389:             * Returns <tt>true</tt> if and only if <tt>autoExpand</tt> is turned on.
0390:             */
0391:            public abstract boolean isAutoExpand();
0392:
0393:            /**
0394:             * Turns on or off <tt>autoExpand</tt>.
0395:             */
0396:            public abstract IoBuffer setAutoExpand(boolean autoExpand);
0397:
0398:            /**
0399:             * Returns <tt>true</tt> if and only if <tt>autoShrink</tt> is turned on.
0400:             */
0401:            public abstract boolean isAutoShrink();
0402:
0403:            /**
0404:             * Turns on or off <tt>autoShrink</tt>.
0405:             */
0406:            public abstract IoBuffer setAutoShrink(boolean autoShrink);
0407:
0408:            /**
0409:             * Changes the capacity and limit of this buffer so this buffer get
0410:             * the specified <tt>expectedRemaining</tt> room from the current position.
0411:             * This method works even if you didn't set <tt>autoExpand</tt> to
0412:             * <tt>true</tt>.
0413:             */
0414:            public abstract IoBuffer expand(int expectedRemaining);
0415:
0416:            /**
0417:             * Changes the capacity and limit of this buffer so this buffer get
0418:             * the specified <tt>expectedRemaining</tt> room from the specified
0419:             * <tt>position</tt>.
0420:             * This method works even if you didn't set <tt>autoExpand</tt> to
0421:             * <tt>true</tt>.
0422:             */
0423:            public abstract IoBuffer expand(int position, int expectedRemaining);
0424:
0425:            /**
0426:             * Changes the capacity of this buffer so this buffer occupies as less
0427:             * memory as possible while retaining the position, limit and the
0428:             * buffer content between the position and limit.  The capacity of the
0429:             * buffer never becomes less than {@link #minimumCapacity()}.
0430:             * The mark is discarded once the capacity changes.
0431:             */
0432:            public abstract IoBuffer shrink();
0433:
0434:            /**
0435:             * @see java.nio.Buffer#position()
0436:             */
0437:            public abstract int position();
0438:
0439:            /**
0440:             * @see java.nio.Buffer#position(int)
0441:             */
0442:            public abstract IoBuffer position(int newPosition);
0443:
0444:            /**
0445:             * @see java.nio.Buffer#limit()
0446:             */
0447:            public abstract int limit();
0448:
0449:            /**
0450:             * @see java.nio.Buffer#limit(int)
0451:             */
0452:            public abstract IoBuffer limit(int newLimit);
0453:
0454:            /**
0455:             * @see java.nio.Buffer#mark()
0456:             */
0457:            public abstract IoBuffer mark();
0458:
0459:            /**
0460:             * Returns the position of the current mark.  This method returns <tt>-1</tt> if no
0461:             * mark is set.
0462:             */
0463:            public abstract int markValue();
0464:
0465:            /**
0466:             * @see java.nio.Buffer#reset()
0467:             */
0468:            public abstract IoBuffer reset();
0469:
0470:            /**
0471:             * @see java.nio.Buffer#clear()
0472:             */
0473:            public abstract IoBuffer clear();
0474:
0475:            /**
0476:             * Clears this buffer and fills its content with <tt>NUL</tt>.
0477:             * The position is set to zero, the limit is set to the capacity,
0478:             * and the mark is discarded.
0479:             */
0480:            public abstract IoBuffer sweep();
0481:
0482:            /**
0483:             * Clears this buffer and fills its content with <tt>value</tt>.
0484:             * The position is set to zero, the limit is set to the capacity,
0485:             * and the mark is discarded.
0486:             */
0487:            public abstract IoBuffer sweep(byte value);
0488:
0489:            /**
0490:             * @see java.nio.Buffer#flip()
0491:             */
0492:            public abstract IoBuffer flip();
0493:
0494:            /**
0495:             * @see java.nio.Buffer#rewind()
0496:             */
0497:            public abstract IoBuffer rewind();
0498:
0499:            /**
0500:             * @see java.nio.Buffer#remaining()
0501:             */
0502:            public abstract int remaining();
0503:
0504:            /**
0505:             * @see java.nio.Buffer#hasRemaining()
0506:             */
0507:            public abstract boolean hasRemaining();
0508:
0509:            /**
0510:             * @see ByteBuffer#duplicate()
0511:             */
0512:            public abstract IoBuffer duplicate();
0513:
0514:            /**
0515:             * @see ByteBuffer#slice()
0516:             */
0517:            public abstract IoBuffer slice();
0518:
0519:            /**
0520:             * @see ByteBuffer#asReadOnlyBuffer()
0521:             */
0522:            public abstract IoBuffer asReadOnlyBuffer();
0523:
0524:            /**
0525:             * @see ByteBuffer#hasArray()
0526:             */
0527:            public abstract boolean hasArray();
0528:
0529:            /**
0530:             * @see ByteBuffer#array()
0531:             */
0532:            public abstract byte[] array();
0533:
0534:            /**
0535:             * @see ByteBuffer#arrayOffset()
0536:             */
0537:            public abstract int arrayOffset();
0538:
0539:            /**
0540:             * @see ByteBuffer#get()
0541:             */
0542:            public abstract byte get();
0543:
0544:            /**
0545:             * Reads one unsigned byte as a short integer.
0546:             */
0547:            public abstract short getUnsigned();
0548:
0549:            /**
0550:             * @see ByteBuffer#put(byte)
0551:             */
0552:            public abstract IoBuffer put(byte b);
0553:
0554:            /**
0555:             * @see ByteBuffer#get(int)
0556:             */
0557:            public abstract byte get(int index);
0558:
0559:            /**
0560:             * Reads one byte as an unsigned short integer.
0561:             */
0562:            public abstract short getUnsigned(int index);
0563:
0564:            /**
0565:             * @see ByteBuffer#put(int, byte)
0566:             */
0567:            public abstract IoBuffer put(int index, byte b);
0568:
0569:            /**
0570:             * @see ByteBuffer#get(byte[], int, int)
0571:             */
0572:            public abstract IoBuffer get(byte[] dst, int offset, int length);
0573:
0574:            /**
0575:             * @see ByteBuffer#get(byte[])
0576:             */
0577:            public abstract IoBuffer get(byte[] dst);
0578:
0579:            /**
0580:             * TODO document me.
0581:             */
0582:            public abstract IoBuffer getSlice(int index, int length);
0583:
0584:            /**
0585:             * TODO document me.
0586:             */
0587:            public abstract IoBuffer getSlice(int length);
0588:
0589:            /**
0590:             * Writes the content of the specified <tt>src</tt> into this buffer.
0591:             */
0592:            public abstract IoBuffer put(ByteBuffer src);
0593:
0594:            /**
0595:             * Writes the content of the specified <tt>src</tt> into this buffer.
0596:             */
0597:            public abstract IoBuffer put(IoBuffer src);
0598:
0599:            /**
0600:             * @see ByteBuffer#put(byte[], int, int)
0601:             */
0602:            public abstract IoBuffer put(byte[] src, int offset, int length);
0603:
0604:            /**
0605:             * @see ByteBuffer#put(byte[])
0606:             */
0607:            public abstract IoBuffer put(byte[] src);
0608:
0609:            /**
0610:             * @see ByteBuffer#compact()
0611:             */
0612:            public abstract IoBuffer compact();
0613:
0614:            /**
0615:             * @see ByteBuffer#order()
0616:             */
0617:            public abstract ByteOrder order();
0618:
0619:            /**
0620:             * @see ByteBuffer#order(ByteOrder)
0621:             */
0622:            public abstract IoBuffer order(ByteOrder bo);
0623:
0624:            /**
0625:             * @see ByteBuffer#getChar()
0626:             */
0627:            public abstract char getChar();
0628:
0629:            /**
0630:             * @see ByteBuffer#putChar(char)
0631:             */
0632:            public abstract IoBuffer putChar(char value);
0633:
0634:            /**
0635:             * @see ByteBuffer#getChar(int)
0636:             */
0637:            public abstract char getChar(int index);
0638:
0639:            /**
0640:             * @see ByteBuffer#putChar(int, char)
0641:             */
0642:            public abstract IoBuffer putChar(int index, char value);
0643:
0644:            /**
0645:             * @see ByteBuffer#asCharBuffer()
0646:             */
0647:            public abstract CharBuffer asCharBuffer();
0648:
0649:            /**
0650:             * @see ByteBuffer#getShort()
0651:             */
0652:            public abstract short getShort();
0653:
0654:            /**
0655:             * Reads two bytes unsigned integer.
0656:             */
0657:            public abstract int getUnsignedShort();
0658:
0659:            /**
0660:             * @see ByteBuffer#putShort(short)
0661:             */
0662:            public abstract IoBuffer putShort(short value);
0663:
0664:            /**
0665:             * @see ByteBuffer#getShort()
0666:             */
0667:            public abstract short getShort(int index);
0668:
0669:            /**
0670:             * Reads two bytes unsigned integer.
0671:             */
0672:            public abstract int getUnsignedShort(int index);
0673:
0674:            /**
0675:             * @see ByteBuffer#putShort(int, short)
0676:             */
0677:            public abstract IoBuffer putShort(int index, short value);
0678:
0679:            /**
0680:             * @see ByteBuffer#asShortBuffer()
0681:             */
0682:            public abstract ShortBuffer asShortBuffer();
0683:
0684:            /**
0685:             * @see ByteBuffer#getInt()
0686:             */
0687:            public abstract int getInt();
0688:
0689:            /**
0690:             * Reads four bytes unsigned integer.
0691:             */
0692:            public abstract long getUnsignedInt();
0693:
0694:            /**
0695:             * Relative <i>get</i> method for reading a medium int value.
0696:             *
0697:             * <p> Reads the next three bytes at this buffer's current position,
0698:             * composing them into an int value according to the current byte order,
0699:             * and then increments the position by three.</p>
0700:             *
0701:             * @return  The medium int value at the buffer's current position
0702:             */
0703:            public abstract int getMediumInt();
0704:
0705:            /**
0706:             * Relative <i>get</i> method for reading an unsigned medium int value.
0707:             *
0708:             * <p> Reads the next three bytes at this buffer's current position,
0709:             * composing them into an int value according to the current byte order,
0710:             * and then increments the position by three.</p>
0711:             *
0712:             * @return  The unsigned medium int value at the buffer's current position
0713:             */
0714:            public abstract int getUnsignedMediumInt();
0715:
0716:            /**
0717:             * Absolute <i>get</i> method for reading a medium int value.
0718:             *
0719:             * <p> Reads the next three bytes at this buffer's current position,
0720:             * composing them into an int value according to the current byte order.</p>
0721:             *
0722:             * @param index  The index from which the medium int will be read
0723:             * @return  The medium int value at the given index
0724:             *
0725:             * @throws  IndexOutOfBoundsException
0726:             *          If <tt>index</tt> is negative
0727:             *          or not smaller than the buffer's limit
0728:             */
0729:            public abstract int getMediumInt(int index);
0730:
0731:            /**
0732:             * Absolute <i>get</i> method for reading an unsigned medium int value.
0733:             *
0734:             * <p> Reads the next three bytes at this buffer's current position,
0735:             * composing them into an int value according to the current byte order.</p>
0736:             *
0737:             * @param index  The index from which the unsigned medium int will be read
0738:             * @return  The unsigned medium int value at the given index
0739:             *
0740:             * @throws  IndexOutOfBoundsException
0741:             *          If <tt>index</tt> is negative
0742:             *          or not smaller than the buffer's limit
0743:             */
0744:            public abstract int getUnsignedMediumInt(int index);
0745:
0746:            /**
0747:             * Relative <i>put</i> method for writing a medium int
0748:             * value.
0749:             *
0750:             * <p> Writes three bytes containing the given int value, in the
0751:             * current byte order, into this buffer at the current position, and then
0752:             * increments the position by three.</p>
0753:             *
0754:             * @param  value
0755:             *         The medium int value to be written
0756:             *
0757:             * @return  This buffer
0758:             *
0759:             * @throws  BufferOverflowException
0760:             *          If there are fewer than three bytes
0761:             *          remaining in this buffer
0762:             *
0763:             * @throws  ReadOnlyBufferException
0764:             *          If this buffer is read-only
0765:             */
0766:            public abstract IoBuffer putMediumInt(int value);
0767:
0768:            /**
0769:             * Absolute <i>put</i> method for writing a medium int
0770:             * value.
0771:             *
0772:             * <p> Writes three bytes containing the given int value, in the
0773:             * current byte order, into this buffer at the given index.</p>
0774:             *
0775:             * @param  index
0776:             *         The index at which the bytes will be written
0777:             *
0778:             * @param  value
0779:             *         The medium int value to be written
0780:             *
0781:             * @return  This buffer
0782:             *
0783:             * @throws  IndexOutOfBoundsException
0784:             *          If <tt>index</tt> is negative
0785:             *          or not smaller than the buffer's limit,
0786:             *          minus three
0787:             *
0788:             * @throws  ReadOnlyBufferException
0789:             *          If this buffer is read-only
0790:             */
0791:            public abstract IoBuffer putMediumInt(int index, int value);
0792:
0793:            /**
0794:             * @see ByteBuffer#putInt(int)
0795:             */
0796:            public abstract IoBuffer putInt(int value);
0797:
0798:            /**
0799:             * @see ByteBuffer#getInt(int)
0800:             */
0801:            public abstract int getInt(int index);
0802:
0803:            /**
0804:             * Reads four bytes unsigned integer.
0805:             */
0806:            public abstract long getUnsignedInt(int index);
0807:
0808:            /**
0809:             * @see ByteBuffer#putInt(int, int)
0810:             */
0811:            public abstract IoBuffer putInt(int index, int value);
0812:
0813:            /**
0814:             * @see ByteBuffer#asIntBuffer()
0815:             */
0816:            public abstract IntBuffer asIntBuffer();
0817:
0818:            /**
0819:             * @see ByteBuffer#getLong()
0820:             */
0821:            public abstract long getLong();
0822:
0823:            /**
0824:             * @see ByteBuffer#putLong(int, long)
0825:             */
0826:            public abstract IoBuffer putLong(long value);
0827:
0828:            /**
0829:             * @see ByteBuffer#getLong(int)
0830:             */
0831:            public abstract long getLong(int index);
0832:
0833:            /**
0834:             * @see ByteBuffer#putLong(int, long)
0835:             */
0836:            public abstract IoBuffer putLong(int index, long value);
0837:
0838:            /**
0839:             * @see ByteBuffer#asLongBuffer()
0840:             */
0841:            public abstract LongBuffer asLongBuffer();
0842:
0843:            /**
0844:             * @see ByteBuffer#getFloat()
0845:             */
0846:            public abstract float getFloat();
0847:
0848:            /**
0849:             * @see ByteBuffer#putFloat(float)
0850:             */
0851:            public abstract IoBuffer putFloat(float value);
0852:
0853:            /**
0854:             * @see ByteBuffer#getFloat(int)
0855:             */
0856:            public abstract float getFloat(int index);
0857:
0858:            /**
0859:             * @see ByteBuffer#putFloat(int, float)
0860:             */
0861:            public abstract IoBuffer putFloat(int index, float value);
0862:
0863:            /**
0864:             * @see ByteBuffer#asFloatBuffer()
0865:             */
0866:            public abstract FloatBuffer asFloatBuffer();
0867:
0868:            /**
0869:             * @see ByteBuffer#getDouble()
0870:             */
0871:            public abstract double getDouble();
0872:
0873:            /**
0874:             * @see ByteBuffer#putDouble(double)
0875:             */
0876:            public abstract IoBuffer putDouble(double value);
0877:
0878:            /**
0879:             * @see ByteBuffer#getDouble(int)
0880:             */
0881:            public abstract double getDouble(int index);
0882:
0883:            /**
0884:             * @see ByteBuffer#putDouble(int, double)
0885:             */
0886:            public abstract IoBuffer putDouble(int index, double value);
0887:
0888:            /**
0889:             * @see ByteBuffer#asDoubleBuffer()
0890:             */
0891:            public abstract DoubleBuffer asDoubleBuffer();
0892:
0893:            /**
0894:             * Returns an {@link InputStream} that reads the data from this buffer.
0895:             * {@link InputStream#read()} returns <tt>-1</tt> if the buffer position
0896:             * reaches to the limit.
0897:             */
0898:            public abstract InputStream asInputStream();
0899:
0900:            /**
0901:             * Returns an {@link OutputStream} that appends the data into this buffer.
0902:             * Please note that the {@link OutputStream#write(int)} will throw a
0903:             * {@link BufferOverflowException} instead of an {@link IOException}
0904:             * in case of buffer overflow.  Please set <tt>autoExpand</tt> property by
0905:             * calling {@link #setAutoExpand(boolean)} to prevent the unexpected runtime
0906:             * exception.
0907:             */
0908:            public abstract OutputStream asOutputStream();
0909:
0910:            /**
0911:             * Returns hexdump of this buffer.  The data and pointer are
0912:             * not changed as a result of this method call.
0913:             *
0914:             * @return
0915:             *  hexidecimal representation of this buffer
0916:             */
0917:            public abstract String getHexDump();
0918:
0919:            /**
0920:             * Return hexdump of this buffer with limited length.
0921:             *
0922:             * @param lengthLimit The maximum number of bytes to dump from
0923:             *                    the current buffer position.
0924:             * @return
0925:             *  hexidecimal representation of this buffer
0926:             */
0927:            public abstract String getHexDump(int lengthLimit);
0928:
0929:            ////////////////////////////////
0930:            // String getters and putters //
0931:            ////////////////////////////////
0932:
0933:            /**
0934:             * Reads a <code>NUL</code>-terminated string from this buffer using the
0935:             * specified <code>decoder</code> and returns it.  This method reads
0936:             * until the limit of this buffer if no <tt>NUL</tt> is found.
0937:             */
0938:            public abstract String getString(CharsetDecoder decoder)
0939:                    throws CharacterCodingException;
0940:
0941:            /**
0942:             * Reads a <code>NUL</code>-terminated string from this buffer using the
0943:             * specified <code>decoder</code> and returns it.
0944:             *
0945:             * @param fieldSize the maximum number of bytes to read
0946:             */
0947:            public abstract String getString(int fieldSize,
0948:                    CharsetDecoder decoder) throws CharacterCodingException;
0949:
0950:            /**
0951:             * Writes the content of <code>in</code> into this buffer using the
0952:             * specified <code>encoder</code>.  This method doesn't terminate
0953:             * string with <tt>NUL</tt>.  You have to do it by yourself.
0954:             *
0955:             * @throws BufferOverflowException if the specified string doesn't fit
0956:             */
0957:            public abstract IoBuffer putString(CharSequence val,
0958:                    CharsetEncoder encoder) throws CharacterCodingException;
0959:
0960:            /**
0961:             * Writes the content of <code>in</code> into this buffer as a
0962:             * <code>NUL</code>-terminated string using the specified
0963:             * <code>encoder</code>.
0964:             * <p>
0965:             * If the charset name of the encoder is UTF-16, you cannot specify
0966:             * odd <code>fieldSize</code>, and this method will append two
0967:             * <code>NUL</code>s as a terminator.
0968:             * <p>
0969:             * Please note that this method doesn't terminate with <code>NUL</code>
0970:             * if the input string is longer than <tt>fieldSize</tt>.
0971:             *
0972:             * @param fieldSize the maximum number of bytes to write
0973:             */
0974:            public abstract IoBuffer putString(CharSequence val, int fieldSize,
0975:                    CharsetEncoder encoder) throws CharacterCodingException;
0976:
0977:            /**
0978:             * Reads a string which has a 16-bit length field before the actual
0979:             * encoded string, using the specified <code>decoder</code> and returns it.
0980:             * This method is a shortcut for <tt>getPrefixedString(2, decoder)</tt>.
0981:             */
0982:            public abstract String getPrefixedString(CharsetDecoder decoder)
0983:                    throws CharacterCodingException;
0984:
0985:            /**
0986:             * Reads a string which has a length field before the actual
0987:             * encoded string, using the specified <code>decoder</code> and returns it.
0988:             *
0989:             * @param prefixLength the length of the length field (1, 2, or 4)
0990:             */
0991:            public abstract String getPrefixedString(int prefixLength,
0992:                    CharsetDecoder decoder) throws CharacterCodingException;
0993:
0994:            /**
0995:             * Writes the content of <code>in</code> into this buffer as a
0996:             * string which has a 16-bit length field before the actual
0997:             * encoded string, using the specified <code>encoder</code>.
0998:             * This method is a shortcut for <tt>putPrefixedString(in, 2, 0, encoder)</tt>.
0999:             *
1000:             * @throws BufferOverflowException if the specified string doesn't fit
1001:             */
1002:            public abstract IoBuffer putPrefixedString(CharSequence in,
1003:                    CharsetEncoder encoder) throws CharacterCodingException;
1004:
1005:            /**
1006:             * Writes the content of <code>in</code> into this buffer as a
1007:             * string which has a 16-bit length field before the actual
1008:             * encoded string, using the specified <code>encoder</code>.
1009:             * This method is a shortcut for <tt>putPrefixedString(in, prefixLength, 0, encoder)</tt>.
1010:             *
1011:             * @param prefixLength the length of the length field (1, 2, or 4)
1012:             *
1013:             * @throws BufferOverflowException if the specified string doesn't fit
1014:             */
1015:            public abstract IoBuffer putPrefixedString(CharSequence in,
1016:                    int prefixLength, CharsetEncoder encoder)
1017:                    throws CharacterCodingException;
1018:
1019:            /**
1020:             * Writes the content of <code>in</code> into this buffer as a
1021:             * string which has a 16-bit length field before the actual
1022:             * encoded string, using the specified <code>encoder</code>.
1023:             * This method is a shortcut for <tt>putPrefixedString(in, prefixLength, padding, ( byte ) 0, encoder)</tt>.
1024:             *
1025:             * @param prefixLength the length of the length field (1, 2, or 4)
1026:             * @param padding      the number of padded <tt>NUL</tt>s (1 (or 0), 2, or 4)
1027:             *
1028:             * @throws BufferOverflowException if the specified string doesn't fit
1029:             */
1030:            public abstract IoBuffer putPrefixedString(CharSequence in,
1031:                    int prefixLength, int padding, CharsetEncoder encoder)
1032:                    throws CharacterCodingException;
1033:
1034:            /**
1035:             * Writes the content of <code>in</code> into this buffer as a
1036:             * string which has a 16-bit length field before the actual
1037:             * encoded string, using the specified <code>encoder</code>.
1038:             *
1039:             * @param prefixLength the length of the length field (1, 2, or 4)
1040:             * @param padding      the number of padded bytes (1 (or 0), 2, or 4)
1041:             * @param padValue     the value of padded bytes
1042:             *
1043:             * @throws BufferOverflowException if the specified string doesn't fit
1044:             */
1045:            public abstract IoBuffer putPrefixedString(CharSequence val,
1046:                    int prefixLength, int padding, byte padValue,
1047:                    CharsetEncoder encoder) throws CharacterCodingException;
1048:
1049:            /**
1050:             * Reads a Java object from the buffer using the context {@link ClassLoader}
1051:             * of the current thread.
1052:             */
1053:            public abstract Object getObject() throws ClassNotFoundException;
1054:
1055:            /**
1056:             * Reads a Java object from the buffer using the specified <tt>classLoader</tt>.
1057:             */
1058:            public abstract Object getObject(final ClassLoader classLoader)
1059:                    throws ClassNotFoundException;
1060:
1061:            /**
1062:             * Writes the specified Java object to the buffer.
1063:             */
1064:            public abstract IoBuffer putObject(Object o);
1065:
1066:            /**
1067:             * Returns <tt>true</tt> if this buffer contains a data which has a data
1068:             * length as a prefix and the buffer has remaining data as enough as
1069:             * specified in the data length field.  This method is identical with
1070:             * <tt>prefixedDataAvailable( prefixLength, Integer.MAX_VALUE )</tt>.
1071:             * Please not that using this method can allow DoS (Denial of Service)
1072:             * attack in case the remote peer sends too big data length value.
1073:             * It is recommended to use {@link #prefixedDataAvailable(int, int)}
1074:             * instead.
1075:             *
1076:             * @param prefixLength the length of the prefix field (1, 2, or 4)
1077:             *
1078:             * @throws IllegalArgumentException if prefixLength is wrong
1079:             * @throws BufferDataException      if data length is negative
1080:             */
1081:            public abstract boolean prefixedDataAvailable(int prefixLength);
1082:
1083:            /**
1084:             * Returns <tt>true</tt> if this buffer contains a data which has a data
1085:             * length as a prefix and the buffer has remaining data as enough as
1086:             * specified in the data length field.
1087:             *
1088:             * @param prefixLength  the length of the prefix field (1, 2, or 4)
1089:             * @param maxDataLength the allowed maximum of the read data length
1090:             *
1091:             * @throws IllegalArgumentException if prefixLength is wrong
1092:             * @throws BufferDataException      if data length is negative or greater then <tt>maxDataLength</tt>
1093:             */
1094:            public abstract boolean prefixedDataAvailable(int prefixLength,
1095:                    int maxDataLength);
1096:
1097:            /////////////////////
1098:            // IndexOf methods //
1099:            /////////////////////
1100:
1101:            /**
1102:             * Returns the first occurence position of the specified byte from the current position to
1103:             * the current limit.
1104:             *
1105:             * @return <tt>-1</tt> if the specified byte is not found
1106:             */
1107:            public abstract int indexOf(byte b);
1108:
1109:            //////////////////////////
1110:            // Skip or fill methods //
1111:            //////////////////////////
1112:
1113:            /**
1114:             * Forwards the position of this buffer as the specified <code>size</code>
1115:             * bytes.
1116:             */
1117:            public abstract IoBuffer skip(int size);
1118:
1119:            /**
1120:             * Fills this buffer with the specified value.
1121:             * This method moves buffer position forward.
1122:             */
1123:            public abstract IoBuffer fill(byte value, int size);
1124:
1125:            /**
1126:             * Fills this buffer with the specified value.
1127:             * This method does not change buffer position.
1128:             */
1129:            public abstract IoBuffer fillAndReset(byte value, int size);
1130:
1131:            /**
1132:             * Fills this buffer with <code>NUL (0x00)</code>.
1133:             * This method moves buffer position forward.
1134:             */
1135:            public abstract IoBuffer fill(int size);
1136:
1137:            /**
1138:             * Fills this buffer with <code>NUL (0x00)</code>.
1139:             * This method does not change buffer position.
1140:             */
1141:            public abstract IoBuffer fillAndReset(int size);
1142:
1143:            //////////////////////////
1144:            // Enum methods         //
1145:            //////////////////////////
1146:
1147:            /**
1148:             * Reads a byte from the buffer and returns the correlating enum constant defined
1149:             * by the specified enum type.
1150:             *
1151:             * @param <E> The enum type to return
1152:             * @param enumClass  The enum's class object
1153:             */
1154:            public abstract <E extends Enum<E>> E getEnum(Class<E> enumClass);
1155:
1156:            /**
1157:             * Reads a byte from the buffer and returns the correlating enum constant defined
1158:             * by the specified enum type.
1159:             *
1160:             * @param <E> The enum type to return
1161:             * @param index  the index from which the byte will be read
1162:             * @param enumClass  The enum's class object
1163:             */
1164:            public abstract <E extends Enum<E>> E getEnum(int index,
1165:                    Class<E> enumClass);
1166:
1167:            /**
1168:             * Reads a short from the buffer and returns the correlating enum constant defined
1169:             * by the specified enum type.
1170:             *
1171:             * @param <E> The enum type to return
1172:             * @param enumClass  The enum's class object
1173:             */
1174:            public abstract <E extends Enum<E>> E getEnumShort(
1175:                    Class<E> enumClass);
1176:
1177:            /**
1178:             * Reads a short from the buffer and returns the correlating enum constant defined
1179:             * by the specified enum type.
1180:             *
1181:             * @param <E> The enum type to return
1182:             * @param index  the index from which the bytes will be read
1183:             * @param enumClass  The enum's class object
1184:             */
1185:            public abstract <E extends Enum<E>> E getEnumShort(int index,
1186:                    Class<E> enumClass);
1187:
1188:            /**
1189:             * Reads an int from the buffer and returns the correlating enum constant defined
1190:             * by the specified enum type.
1191:             *
1192:             * @param <E> The enum type to return
1193:             * @param enumClass  The enum's class object
1194:             */
1195:            public abstract <E extends Enum<E>> E getEnumInt(Class<E> enumClass);
1196:
1197:            /**
1198:             * Reads an int from the buffer and returns the correlating enum constant defined
1199:             * by the specified enum type.
1200:             *
1201:             * @param <E> The enum type to return
1202:             * @param index  the index from which the bytes will be read
1203:             * @param enumClass  The enum's class object
1204:             */
1205:            public abstract <E extends Enum<E>> E getEnumInt(int index,
1206:                    Class<E> enumClass);
1207:
1208:            /**
1209:             * Writes an enum's ordinal value to the buffer as a byte.
1210:             *
1211:             * @param e  The enum to write to the buffer
1212:             */
1213:            public abstract IoBuffer putEnum(Enum<?> e);
1214:
1215:            /**
1216:             * Writes an enum's ordinal value to the buffer as a byte.
1217:             *
1218:             * @param index The index at which the byte will be written
1219:             * @param e  The enum to write to the buffer
1220:             */
1221:            public abstract IoBuffer putEnum(int index, Enum<?> e);
1222:
1223:            /**
1224:             * Writes an enum's ordinal value to the buffer as a short.
1225:             *
1226:             * @param e  The enum to write to the buffer
1227:             */
1228:            public abstract IoBuffer putEnumShort(Enum<?> e);
1229:
1230:            /**
1231:             * Writes an enum's ordinal value to the buffer as a short.
1232:             *
1233:             * @param index The index at which the bytes will be written
1234:             * @param e  The enum to write to the buffer
1235:             */
1236:            public abstract IoBuffer putEnumShort(int index, Enum<?> e);
1237:
1238:            /**
1239:             * Writes an enum's ordinal value to the buffer as an integer.
1240:             *
1241:             * @param e  The enum to write to the buffer
1242:             */
1243:            public abstract IoBuffer putEnumInt(Enum<?> e);
1244:
1245:            /**
1246:             * Writes an enum's ordinal value to the buffer as an integer.
1247:             *
1248:             * @param index The index at which the bytes will be written
1249:             * @param e  The enum to write to the buffer
1250:             */
1251:            public abstract IoBuffer putEnumInt(int index, Enum<?> e);
1252:
1253:            //////////////////////////
1254:            // EnumSet methods      //
1255:            //////////////////////////
1256:
1257:            /**
1258:             * Reads a byte sized bit vector and converts it to an {@link EnumSet}.
1259:             *
1260:             * <p>Each bit is mapped to a value in the specified enum.  The least significant
1261:             * bit maps to the first entry in the specified enum and each subsequent bit maps
1262:             * to each subsequent bit as mapped to the subsequent enum value.</p>
1263:             *
1264:             * @param <E>  the enum type
1265:             * @param enumClass  the enum class used to create the EnumSet
1266:             * @return the EnumSet representation of the bit vector
1267:             */
1268:            public abstract <E extends Enum<E>> EnumSet<E> getEnumSet(
1269:                    Class<E> enumClass);
1270:
1271:            /**
1272:             * Reads a byte sized bit vector and converts it to an {@link EnumSet}.
1273:             *
1274:             * @see #getEnumSet(Class)
1275:             * @param <E>  the enum type
1276:             * @param index  the index from which the byte will be read
1277:             * @param enumClass  the enum class used to create the EnumSet
1278:             * @return the EnumSet representation of the bit vector
1279:             */
1280:            public abstract <E extends Enum<E>> EnumSet<E> getEnumSet(
1281:                    int index, Class<E> enumClass);
1282:
1283:            /**
1284:             * Reads a short sized bit vector and converts it to an {@link EnumSet}.
1285:             *
1286:             * @see #getEnumSet(Class)
1287:             * @param <E>  the enum type
1288:             * @param enumClass  the enum class used to create the EnumSet
1289:             * @return the EnumSet representation of the bit vector
1290:             */
1291:            public abstract <E extends Enum<E>> EnumSet<E> getEnumSetShort(
1292:                    Class<E> enumClass);
1293:
1294:            /**
1295:             * Reads a short sized bit vector and converts it to an {@link EnumSet}.
1296:             *
1297:             * @see #getEnumSet(Class)
1298:             * @param <E>  the enum type
1299:             * @param index  the index from which the bytes will be read
1300:             * @param enumClass  the enum class used to create the EnumSet
1301:             * @return the EnumSet representation of the bit vector
1302:             */
1303:            public abstract <E extends Enum<E>> EnumSet<E> getEnumSetShort(
1304:                    int index, Class<E> enumClass);
1305:
1306:            /**
1307:             * Reads an int sized bit vector and converts it to an {@link EnumSet}.
1308:             *
1309:             * @see #getEnumSet(Class)
1310:             * @param <E>  the enum type
1311:             * @param enumClass  the enum class used to create the EnumSet
1312:             * @return the EnumSet representation of the bit vector
1313:             */
1314:            public abstract <E extends Enum<E>> EnumSet<E> getEnumSetInt(
1315:                    Class<E> enumClass);
1316:
1317:            /**
1318:             * Reads an int sized bit vector and converts it to an {@link EnumSet}.
1319:             *
1320:             * @see #getEnumSet(Class)
1321:             * @param <E>  the enum type
1322:             * @param index  the index from which the bytes will be read
1323:             * @param enumClass  the enum class used to create the EnumSet
1324:             * @return the EnumSet representation of the bit vector
1325:             */
1326:            public abstract <E extends Enum<E>> EnumSet<E> getEnumSetInt(
1327:                    int index, Class<E> enumClass);
1328:
1329:            /**
1330:             * Reads a long sized bit vector and converts it to an {@link EnumSet}.
1331:             *
1332:             * @see #getEnumSet(Class)
1333:             * @param <E>  the enum type
1334:             * @param enumClass  the enum class used to create the EnumSet
1335:             * @return the EnumSet representation of the bit vector
1336:             */
1337:            public abstract <E extends Enum<E>> EnumSet<E> getEnumSetLong(
1338:                    Class<E> enumClass);
1339:
1340:            /**
1341:             * Reads a long sized bit vector and converts it to an {@link EnumSet}.
1342:             *
1343:             * @see #getEnumSet(Class)
1344:             * @param <E>  the enum type
1345:             * @param index  the index from which the bytes will be read
1346:             * @param enumClass  the enum class used to create the EnumSet
1347:             * @return the EnumSet representation of the bit vector
1348:             */
1349:            public abstract <E extends Enum<E>> EnumSet<E> getEnumSetLong(
1350:                    int index, Class<E> enumClass);
1351:
1352:            /**
1353:             * Writes the specified {@link Set} to the buffer as a byte sized bit vector.
1354:             *
1355:             * @param <E> the enum type of the Set
1356:             * @param set  the enum set to write to the buffer
1357:             */
1358:            public abstract <E extends Enum<E>> IoBuffer putEnumSet(Set<E> set);
1359:
1360:            /**
1361:             * Writes the specified {@link Set} to the buffer as a byte sized bit vector.
1362:             *
1363:             * @param <E> the enum type of the Set
1364:             * @param index  the index at which the byte will be written
1365:             * @param set  the enum set to write to the buffer
1366:             */
1367:            public abstract <E extends Enum<E>> IoBuffer putEnumSet(int index,
1368:                    Set<E> set);
1369:
1370:            /**
1371:             * Writes the specified {@link Set} to the buffer as a short sized bit vector.
1372:             *
1373:             * @param <E> the enum type of the Set
1374:             * @param set  the enum set to write to the buffer
1375:             */
1376:            public abstract <E extends Enum<E>> IoBuffer putEnumSetShort(
1377:                    Set<E> set);
1378:
1379:            /**
1380:             * Writes the specified {@link Set} to the buffer as a short sized bit vector.
1381:             *
1382:             * @param <E> the enum type of the Set
1383:             * @param index  the index at which the bytes will be written
1384:             * @param set  the enum set to write to the buffer
1385:             */
1386:            public abstract <E extends Enum<E>> IoBuffer putEnumSetShort(
1387:                    int index, Set<E> set);
1388:
1389:            /**
1390:             * Writes the specified {@link Set} to the buffer as an int sized bit vector.
1391:             *
1392:             * @param <E> the enum type of the Set
1393:             * @param set  the enum set to write to the buffer
1394:             */
1395:            public abstract <E extends Enum<E>> IoBuffer putEnumSetInt(
1396:                    Set<E> set);
1397:
1398:            /**
1399:             * Writes the specified {@link Set} to the buffer as an int sized bit vector.
1400:             *
1401:             * @param <E> the enum type of the Set
1402:             * @param index  the index at which the bytes will be written
1403:             * @param set  the enum set to write to the buffer
1404:             */
1405:            public abstract <E extends Enum<E>> IoBuffer putEnumSetInt(
1406:                    int index, Set<E> set);
1407:
1408:            /**
1409:             * Writes the specified {@link Set} to the buffer as a long sized bit vector.
1410:             *
1411:             * @param <E> the enum type of the Set
1412:             * @param set  the enum set to write to the buffer
1413:             */
1414:            public abstract <E extends Enum<E>> IoBuffer putEnumSetLong(
1415:                    Set<E> set);
1416:
1417:            /**
1418:             * Writes the specified {@link Set} to the buffer as a long sized bit vector.
1419:             *
1420:             * @param <E> the enum type of the Set
1421:             * @param index  the index at which the bytes will be written
1422:             * @param set  the enum set to write to the buffer
1423:             */
1424:            public abstract <E extends Enum<E>> IoBuffer putEnumSetLong(
1425:                    int index, Set<E> set);
1426:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.