2046 lines · 55.8 KB · Java
RawDownload
     * is read-only.  </p>     *     * @return  The new byte buffer     */    public abstract ByteBuffer slice();     /**     * Creates a new byte buffer that shares this buffer's content.     *     * <p> The content of the new buffer will be that of this buffer.  Changes     * to this buffer's content will be visible in the new buffer, and vice     * versa; the two buffers' position, limit, and mark values will be     * independent.     *     * <p> The new buffer's capacity, limit, position, and mark values will be     * identical to those of this buffer.  The new buffer will be direct if,     * and only if, this buffer is direct, and it will be read-only if, and     * only if, this buffer is read-only.  </p>     *     * @return  The new byte buffer     */    public abstract ByteBuffer duplicate();     /**     * Creates a new, read-only byte buffer that shares this buffer's     * content.     *     * <p> The content of the new buffer will be that of this buffer.  Changes     * to this buffer's content will be visible in the new buffer; the new     * buffer itself, however, will be read-only and will not allow the shared     * content to be modified.  The two buffers' position, limit, and mark     * values will be independent.     *     * <p> The new buffer's capacity, limit, position, and mark values will be     * identical to those of this buffer.     *     * <p> If this buffer is itself read-only then this method behaves in     * exactly the same way as the {@link #duplicate duplicate} method.  </p>     *     * @return  The new, read-only byte buffer     */    public abstract ByteBuffer asReadOnlyBuffer();      // -- Singleton get/put methods --     /**     * Relative <i>get</i> method.  Reads the byte at this buffer's     * current position, and then increments the position. </p>     *     * @return  The byte at the buffer's current position     *     * @throws  BufferUnderflowException     *          If the buffer's current position is not smaller than its limit     */    public abstract byte get();     /**     * Relative <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.     *     * <p> Writes the given byte into this buffer at the current     * position, and then increments the position. </p>     *     * @param  b     *         The byte to be written     *     * @return  This buffer     *     * @throws  BufferOverflowException     *          If this buffer's current position is not smaller than its limit     *     * @throws  ReadOnlyBufferException     *          If this buffer is read-only     */    public abstract ByteBuffer put(byte b);     /**     * Absolute <i>get</i> method.  Reads the byte at the given     * index. </p>     *     * @param  index     *         The index from which the byte will be read     *     * @return  The byte at the given index     *     * @throws  IndexOutOfBoundsException     *          If <tt>index</tt> is negative     *          or not smaller than the buffer's limit     */    public abstract byte get(int index);     /**     * Absolute <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.     *     * <p> Writes the given byte into this buffer at the given     * index. </p>     *     * @param  index     *         The index at which the byte will be written     *     * @param  b     *         The byte value to be written     *     * @return  This buffer     *     * @throws  IndexOutOfBoundsException     *          If <tt>index</tt> is negative     *          or not smaller than the buffer's limit     *     * @throws  ReadOnlyBufferException     *          If this buffer is read-only     */    public abstract ByteBuffer put(int index, byte b);      // -- Bulk get operations --     /**     * Relative bulk <i>get</i> method.     *     * <p> This method transfers bytes from this buffer into the given     * destination array.  If there are fewer bytes remaining in the     * buffer than are required to satisfy the request, that is, if     * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no     * bytes are transferred and a {@link BufferUnderflowException} is     * thrown.     *     * <p> Otherwise, this method copies <tt>length</tt> bytes from this     * buffer into the given array, starting at the current position of this     * buffer and at the given offset in the array.  The position of this     * buffer is then incremented by <tt>length</tt>.     *     * <p> In other words, an invocation of this method of the form     * <tt>src.get(dst,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as     * the loop     *     * <pre>     *     for (int i = off; i < off + len; i++)     *         dst[i] = src.get(); </pre>     *     * except that it first checks that there are sufficient bytes in     * this buffer and it is potentially much more efficient. </p>     *     * @param  dst     *         The array into which bytes are to be written     *     * @param  offset     *         The offset within the array of the first byte to be     *         written; must be non-negative and no larger than     *         <tt>dst.length</tt>     *     * @param  length     *         The maximum number of bytes to be written to the given     *         array; must be non-negative and no larger than     *         <tt>dst.length - offset</tt>     *     * @return  This buffer     *     * @throws  BufferUnderflowException     *          If there are fewer than <tt>length</tt> bytes     *          remaining in this buffer     *     * @throws  IndexOutOfBoundsException     *          If the preconditions on the <tt>offset</tt> and <tt>length</tt>     *          parameters do not hold     */    public ByteBuffer get(byte[] dst, int offset, int length) {        // [Inferno] <        //checkBounds(offset, length, dst.length);        // [Inferno] =        Buffer.checkBounds(offset, length, dst.length);        // [Inferno] >        if (length > remaining())            throw new BufferUnderflowException();        int end = offset + length;        for (int i = offset; i < end; i++)            dst[i] = get();        return this;    }     /**     * Relative bulk <i>get</i> method.     *     * <p> This method transfers bytes from this buffer into the given     * destination array.  An invocation of this method of the form     * <tt>src.get(a)</tt> behaves in exactly the same way as the invocation     *     * <pre>     *     src.get(a, 0, a.length) </pre>     *     * @return  This buffer     *     * @throws  BufferUnderflowException     *          If there are fewer than <tt>length</tt> bytes     *          remaining in this buffer     */    public ByteBuffer get(byte[] dst) {        return get(dst, 0, dst.length);    }      // -- Bulk put operations --     /**     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.     *     * <p> This method transfers the bytes remaining in the given source     * buffer into this buffer.  If there are more bytes remaining in the     * source buffer than in this buffer, that is, if     * <tt>src.remaining()</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,     * then no bytes are transferred and a {@link     * BufferOverflowException} is thrown.     *     * <p> Otherwise, this method copies     * <i>n</i>&nbsp;=&nbsp;<tt>src.remaining()</tt> bytes from the given     * buffer into this buffer, starting at each buffer's current position.     * The positions of both buffers are then incremented by <i>n</i>.     *     * <p> In other words, an invocation of this method of the form     * <tt>dst.put(src)</tt> has exactly the same effect as the loop     *     * <pre>     *     while (src.hasRemaining())     *         dst.put(src.get()); </pre>     *     * except that it first checks that there is sufficient space in this     * buffer and it is potentially much more efficient. </p>     *     * @param  src     *         The source buffer from which bytes are to be read;     *         must not be this buffer     *     * @return  This buffer     *     * @throws  BufferOverflowException     *          If there is insufficient space in this buffer     *          for the remaining bytes in the source buffer     *     * @throws  IllegalArgumentException     *          If the source buffer is this buffer     *     * @throws  ReadOnlyBufferException     *          If this buffer is read-only     */    public ByteBuffer put(ByteBuffer src) {        if (src == this)            throw new IllegalArgumentException();        int n = src.remaining();        if (n > remaining())            throw new BufferOverflowException();        for (int i = 0; i < n; i++)            put(src.get());        return this;    }     /**     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.     *     * <p> This method transfers bytes into this buffer from the given     * source array.  If there are more bytes to be copied from the array     * than remain in this buffer, that is, if     * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no     * bytes are transferred and a {@link BufferOverflowException} is     * thrown.     *     * <p> Otherwise, this method copies <tt>length</tt> bytes from the     * given array into this buffer, starting at the given offset in the array     * and at the current position of this buffer.  The position of this buffer     * is then incremented by <tt>length</tt>.     *     * <p> In other words, an invocation of this method of the form     * <tt>dst.put(src,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as     * the loop     *     * <pre>     *     for (int i = off; i < off + len; i++)     *         dst.put(a[i]); </pre>     *     * except that it first checks that there is sufficient space in this     * buffer and it is potentially much more efficient. </p>     *     * @param  src     *         The array from which bytes are to be read     *     * @param  offset     *         The offset within the array of the first byte to be read;     *         must be non-negative and no larger than <tt>array.length</tt>     *     * @param  length     *         The number of bytes to be read from the given array;     *         must be non-negative and no larger than     *         <tt>array.length - offset</tt>     *     * @return  This buffer     *     * @throws  BufferOverflowException     *          If there is insufficient space in this buffer     *     * @throws  IndexOutOfBoundsException     *          If the preconditions on the <tt>offset</tt> and <tt>length</tt>     *          parameters do not hold     *     * @throws  ReadOnlyBufferException     *          If this buffer is read-only     */    public ByteBuffer put(byte[] src, int offset, int length) {        // [Inferno] <        //checkBounds(offset, length, src.length);        // [Inferno] =        Buffer.checkBounds(offset, length, src.length);        // [Inferno] >        if (length > remaining())            throw new BufferOverflowException();        int end = offset + length;        for (int i = offset; i < end; i++)            this.put(src[i]);        return this;    }     /**     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.     *     * <p> This method transfers the entire content of the given source     * byte array into this buffer.  An invocation of this method of the     * form <tt>dst.put(a)</tt> behaves in exactly the same way as the     * invocation     *     * <pre>     *     dst.put(a, 0, a.length) </pre>     *     * @return  This buffer     *     * @throws  BufferOverflowException     *          If there is insufficient space in this buffer     *     * @throws  ReadOnlyBufferException     *          If this buffer is read-only     */    public final ByteBuffer put(byte[] src) {        return put(src, 0, src.length);    }                                                                                           // -- Other stuff --     /**     * Tells whether or not this buffer is backed by an accessible byte     * array.     *     * <p> If this method returns <tt>true</tt> then the {@link #array() array}     * and {@link #arrayOffset() arrayOffset} methods may safely be invoked.     * </p>     *     * @return  <tt>true</tt> if, and only if, this buffer     *          is backed by an array and is not read-only     */    public final boolean hasArray() {        return (hb != null) && !isReadOnly;    }     /**     * Returns the byte array that backs this     * buffer&nbsp;&nbsp;<i>(optional operation)</i>.     *     * <p> Modifications to this buffer's content will cause the returned     * array's content to be modified, and vice versa.     *     * <p> Invoke the {@link #hasArray hasArray} method before invoking this     * method in order to ensure that this buffer has an accessible backing     * array.  </p>     *     * @return  The array that backs this buffer     *     * @throws  ReadOnlyBufferException     *          If this buffer is backed by an array but is read-only     *     * @throws  UnsupportedOperationException     *          If this buffer is not backed by an accessible array     */    public final byte[] array() {        if (hb == null)            throw new UnsupportedOperationException();        if (isReadOnly)            throw new ReadOnlyBufferException();        return hb;    }     /**     * Returns the offset within this buffer's backing array of the first     * element of the buffer&nbsp;&nbsp;<i>(optional operation)</i>.     *     * <p> If this buffer is backed by an array then buffer position <i>p</i>     * corresponds to array index <i>p</i>&nbsp;+&nbsp;<tt>arrayOffset()</tt>.     *     * <p> Invoke the {@link #hasArray hasArray} method before invoking this     * method in order to ensure that this buffer has an accessible backing     * array.  </p>     *     * @return  The offset within this buffer's array     *          of the first element of the buffer     *     * @throws  ReadOnlyBufferException     *          If this buffer is backed by an array but is read-only     *     * @throws  UnsupportedOperationException     *          If this buffer is not backed by an accessible array     */    public final int arrayOffset() {        if (hb == null)            throw new UnsupportedOperationException();        if (isReadOnly)            throw new ReadOnlyBufferException();        return offset;    } 

Lines 501–1000 of 2046. Previous lines