org.eclipse.jetty.io

## Class AbstractBuffer

- java.lang.Object
- - org.eclipse.jetty.io.AbstractBuffer

- All Implemented Interfaces:
    Cloneable, Buffer
  Direct Known Subclasses:
    ByteArrayBuffer, DirectNIOBuffer, RandomAccessFileBuffer, View

      public abstract class AbstractBuffer
      extends Object
      implements Buffer

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.eclipse.jetty.io.Buffer

      `Buffer.CaseInsensitve`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static String` | `__IMMUTABLE`
    `protected static String` | `__READONLY`
    `protected static String` | `__READWRITE`
    `protected static String` | `__VOLATILE`
    `protected int` | `_access`
    `protected int` | `_get`
    `protected int` | `_hash`
    `protected int` | `_hashGet`
    `protected int` | `_hashPut`
    `protected int` | `_mark`
    `protected int` | `_put`
    `protected String` | `_string`
    `protected View` | `_view`
    `protected boolean` | `_volatile`

    - ### Fields inherited from interface org.eclipse.jetty.io.Buffer

      `IMMUTABLE, NON_VOLATILE, READONLY, READWRITE, VOLATILE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractBuffer(int access, boolean isVolatile)` Constructor for BufferView

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `byte[]` | `asArray()`
    `Buffer` | `asImmutableBuffer()`
    `Buffer` | `asMutableBuffer()`
    `Buffer` | `asNonVolatileBuffer()`
    `Buffer` | `asReadOnlyBuffer()`
    `Buffer` | `buffer()` Get the underlying buffer.
    `void` | `clear()` Clear the buffer.
    `void` | `compact()` Compact the buffer by discarding bytes before the postion (or mark if set).
    `ByteArrayBuffer` | `duplicate(int access)`
    `boolean` | `equals(Object obj)`
    `boolean` | `equalsIgnoreCase(Buffer b)`
    `byte` | `get()` Get the byte at the current getIndex and increment it.
    `int` | `get(byte[] b, int offset, int length)` Get bytes from the current postion and put them into the passed byte array.
    `Buffer` | `get(int length)`
    `int` | `getIndex()` The index within the buffer that will next be read or written.
    `boolean` | `hasContent()`
    `int` | `hashCode()`
    `boolean` | `isImmutable()`
    `boolean` | `isReadOnly()`
    `boolean` | `isVolatile()`
    `int` | `length()` The number of bytes from the getIndex to the putIndex
    `void` | `mark()` Set the mark to the current getIndex.
    `void` | `mark(int offset)` Set the mark relative to the current getIndex
    `int` | `markIndex()` The current index of the mark.
    `byte` | `peek()` Get the byte at the current getIndex without incrementing the getIndex.
    `Buffer` | `peek(int index, int length)`
    `int` | `poke(int index, Buffer src)` Put the contents of the buffer at the specific index.
    `int` | `poke(int index, byte[] b, int offset, int length)` Put a specific byte to a specific getIndex.
    `int` | `put(Buffer src)` Write the bytes from the source buffer to the current getIndex.
    `void` | `put(byte b)` Put a byte to the current getIndex and increment the getIndex.
    `int` | `put(byte[] b)` Put a byte to the current getIndex and increment the getIndex.
    `int` | `put(byte[] b, int offset, int length)` Put a byte to the current getIndex and increment the getIndex.
    `int` | `putIndex()` The index of the first element that should not be read.
    `int` | `readFrom(InputStream in, int max)` Read the buffer's contents from the input stream
    `void` | `reset()` Reset the current getIndex to the mark
    `void` | `rewind()`
    `void` | `setGetIndex(int getIndex)` Set the buffers start getIndex.
    `void` | `setMarkIndex(int index)` Set a specific value for the mark.
    `void` | `setPutIndex(int putIndex)`
    `int` | `skip(int n)` Skip _content.
    `Buffer` | `slice()`
    `Buffer` | `sliceFromMark()`
    `Buffer` | `sliceFromMark(int length)`
    `int` | `space()` the space remaining in the buffer.
    `String` | `toDebugString()`
    `String` | `toDetailString()`
    `String` | `toString()`
    `String` | `toString(Charset charset)`
    `String` | `toString(String charset)`
    `void` | `writeTo(OutputStream out)` Write the buffer's contents to the output stream

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.jetty.io.Buffer

      `array, capacity, peek, peek, poke`

- - ### Field Detail

    - #### __IMMUTABLE

          protected static final String __IMMUTABLE

      See Also:
        Constant Field Values

    - #### __READONLY

          protected static final String __READONLY

      See Also:
        Constant Field Values

    - #### __READWRITE

          protected static final String __READWRITE

      See Also:
        Constant Field Values

    - #### __VOLATILE

          protected static final String __VOLATILE

      See Also:
        Constant Field Values

    - #### _access

          protected int _access

    - #### _volatile

          protected boolean _volatile

    - #### _get

          protected int _get

    - #### _put

          protected int _put

    - #### _hash

          protected int _hash

    - #### _hashGet

          protected int _hashGet

    - #### _hashPut

          protected int _hashPut

    - #### _mark

          protected int _mark

    - #### _string

          protected String _string

    - #### _view

          protected View _view

  - ### Constructor Detail

    - #### AbstractBuffer

          public AbstractBuffer(int access,
                        boolean isVolatile)

      Constructor for BufferView
      Parameters:
        `access` - 0==IMMUTABLE, 1==READONLY, 2==READWRITE

  - ### Method Detail

    - #### asArray

          public byte[] asArray()

      Specified by:
        `asArray` in interface `Buffer`
      Returns:
        a `byte[]` value of the bytes from the getIndex to the putIndex.

    - #### duplicate

          public ByteArrayBuffer duplicate(int access)

    - #### asNonVolatileBuffer

          public Buffer asNonVolatileBuffer()

      Specified by:
        `asNonVolatileBuffer` in interface `Buffer`
      Returns:
        a non volatile version of this `Buffer` value

    - #### asImmutableBuffer

          public Buffer asImmutableBuffer()

      Specified by:
        `asImmutableBuffer` in interface `Buffer`
      Returns:
        an immutable version of this `Buffer`.

    - #### asReadOnlyBuffer

          public Buffer asReadOnlyBuffer()

      Specified by:
        `asReadOnlyBuffer` in interface `Buffer`
      Returns:
        a readonly version of this `Buffer`.

    - #### asMutableBuffer

          public Buffer asMutableBuffer()

      Specified by:
        `asMutableBuffer` in interface `Buffer`
      Returns:
        an immutable version of this `Buffer`.

    - #### buffer

          public Buffer buffer()

      Description copied from interface: `Buffer`
      Get the underlying buffer. If this buffer wraps a backing buffer.
      Specified by:
        `buffer` in interface `Buffer`
      Returns:
        The root backing buffer or this if there is no backing buffer;

    - #### clear

          public void clear()

      Description copied from interface: `Buffer`
      Clear the buffer. getIndex=0, putIndex=0.
      Specified by:
        `clear` in interface `Buffer`

    - #### compact

          public void compact()

      Description copied from interface: `Buffer`
      Compact the buffer by discarding bytes before the postion (or mark if set). Bytes from the getIndex (or mark) to the putIndex are moved to the beginning of the buffer and the values adjusted accordingly.
      Specified by:
        `compact` in interface `Buffer`

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### equalsIgnoreCase

          public boolean equalsIgnoreCase(Buffer b)

      Specified by:
        `equalsIgnoreCase` in interface `Buffer`
      Returns:
        a `boolean` value true if case sensitive comparison on this buffer

    - #### get

          public byte get()

      Description copied from interface: `Buffer`
      Get the byte at the current getIndex and increment it.
      Specified by:
        `get` in interface `Buffer`
      Returns:
        The `byte` value from the current getIndex.

    - #### get

          public int get(byte[] b,
                int offset,
                int length)

      Description copied from interface: `Buffer`
      Get bytes from the current postion and put them into the passed byte array. The getIndex is incremented by the number of bytes copied into the array.
      Specified by:
        `get` in interface `Buffer`
      Parameters:
        `b` - The byte array to fill.
        `offset` - Offset in the array.
        `length` - The max number of bytes to read.
      Returns:
        The number of bytes actually read.

    - #### get

          public Buffer get(int length)

      Specified by:
        `get` in interface `Buffer`
      Parameters:
        `length` - an `int` value
      Returns:
        a `Buffer` value

    - #### getIndex

          public final int getIndex()

      Description copied from interface: `Buffer`
      The index within the buffer that will next be read or written.
      Specified by:
        `getIndex` in interface `Buffer`
      Returns:
        an `int` value >=0 <= putIndex()

    - #### hasContent

          public boolean hasContent()

      Specified by:
        `hasContent` in interface `Buffer`
      Returns:
        true of putIndex > getIndex

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### isImmutable

          public boolean isImmutable()

      Specified by:
        `isImmutable` in interface `Buffer`
      Returns:
        a `boolean` value true if the buffer is immutable and that neither the buffer contents nor the indexes may be changed.

    - #### isReadOnly

          public boolean isReadOnly()

      Specified by:
        `isReadOnly` in interface `Buffer`
      Returns:
        a `boolean` value true if the buffer is readonly. The buffer indexes may be modified, but the buffer contents may not. For example a View onto an immutable Buffer will be read only.

    - #### isVolatile

          public boolean isVolatile()

      Specified by:
        `isVolatile` in interface `Buffer`
      Returns:
        a `boolean` value true if the buffer contents may change via alternate paths than this buffer. If the contents of this buffer are to be used outside of the current context, then a copy must be made.

    - #### length

          public int length()

      Description copied from interface: `Buffer`
      The number of bytes from the getIndex to the putIndex
      Specified by:
        `length` in interface `Buffer`
      Returns:
        an `int` == putIndex()-getIndex()

    - #### mark

          public void mark()

      Description copied from interface: `Buffer`
      Set the mark to the current getIndex.
      Specified by:
        `mark` in interface `Buffer`

    - #### mark

          public void mark(int offset)

      Description copied from interface: `Buffer`
      Set the mark relative to the current getIndex
      Specified by:
        `mark` in interface `Buffer`
      Parameters:
        `offset` - an `int` value to add to the current getIndex to obtain the mark value.

    - #### markIndex

          public int markIndex()

      Description copied from interface: `Buffer`
      The current index of the mark.
      Specified by:
        `markIndex` in interface `Buffer`
      Returns:
        an `int` index in the buffer or -1 if the mark is not set.

    - #### peek

          public byte peek()

      Description copied from interface: `Buffer`
      Get the byte at the current getIndex without incrementing the getIndex.
      Specified by:
        `peek` in interface `Buffer`
      Returns:
        The `byte` value from the current getIndex.

    - #### peek

          public Buffer peek(int index,
                    int length)

      Specified by:
        `peek` in interface `Buffer`
      Parameters:
        `index` - an `int` value
        `length` - an `int` value
      Returns:
        The `Buffer` value from the requested getIndex.

    - #### poke

          public int poke(int index,
                 Buffer src)

      Description copied from interface: `Buffer`
      Put the contents of the buffer at the specific index.
      Specified by:
        `poke` in interface `Buffer`
      Parameters:
        `index` - an `int` value
        `src` - a `Buffer`. If the source buffer is not modified
      Returns:
        The number of bytes actually poked

    - #### poke

          public int poke(int index,
                 byte[] b,
                 int offset,
                 int length)

      Description copied from interface: `Buffer`
      Put a specific byte to a specific getIndex.
      Specified by:
        `poke` in interface `Buffer`
      Parameters:
        `index` - an `int` value
        `b` - a `byte array` value
      Returns:
        The number of bytes actually poked

    - #### put

          public int put(Buffer src)

      Description copied from interface: `Buffer`
      Write the bytes from the source buffer to the current getIndex.
      Specified by:
        `put` in interface `Buffer`
      Parameters:
        `src` - The source `Buffer` it is not modified.
      Returns:
        The number of bytes actually poked

    - #### put

          public void put(byte b)

      Description copied from interface: `Buffer`
      Put a byte to the current getIndex and increment the getIndex.
      Specified by:
        `put` in interface `Buffer`
      Parameters:
        `b` - a `byte` value

    - #### put

          public int put(byte[] b,
                int offset,
                int length)

      Description copied from interface: `Buffer`
      Put a byte to the current getIndex and increment the getIndex.
      Specified by:
        `put` in interface `Buffer`
      Parameters:
        `b` - a `byte` value
      Returns:
        The number of bytes actually poked

    - #### put

          public int put(byte[] b)

      Description copied from interface: `Buffer`
      Put a byte to the current getIndex and increment the getIndex.
      Specified by:
        `put` in interface `Buffer`
      Parameters:
        `b` - a `byte` value
      Returns:
        The number of bytes actually poked

    - #### putIndex

          public final int putIndex()

      Description copied from interface: `Buffer`
      The index of the first element that should not be read.
      Specified by:
        `putIndex` in interface `Buffer`
      Returns:
        an `int` value >= getIndex()

    - #### reset

          public void reset()

      Description copied from interface: `Buffer`
      Reset the current getIndex to the mark
      Specified by:
        `reset` in interface `Buffer`

    - #### rewind

          public void rewind()

    - #### setGetIndex

          public void setGetIndex(int getIndex)

      Description copied from interface: `Buffer`
      Set the buffers start getIndex.
      Specified by:
        `setGetIndex` in interface `Buffer`
      Parameters:
        `getIndex` - an `int` value

    - #### setMarkIndex

          public void setMarkIndex(int index)

      Description copied from interface: `Buffer`
      Set a specific value for the mark.
      Specified by:
        `setMarkIndex` in interface `Buffer`
      Parameters:
        `index` - an `int` value

    - #### setPutIndex

          public void setPutIndex(int putIndex)

      Specified by:
        `setPutIndex` in interface `Buffer`
      Parameters:
        `putIndex` - an `int` value

    - #### skip

          public int skip(int n)

      Description copied from interface: `Buffer`
      Skip _content. The getIndex is updated by min(remaining(), n)
      Specified by:
        `skip` in interface `Buffer`
      Parameters:
        `n` - The number of bytes to skip
      Returns:
        the number of bytes skipped.

    - #### slice

          public Buffer slice()

      Specified by:
        `slice` in interface `Buffer`
      Returns:
        a volitile `Buffer` from the postion to the putIndex.

    - #### sliceFromMark

          public Buffer sliceFromMark()

      Specified by:
        `sliceFromMark` in interface `Buffer`
      Returns:
        a volitile `Buffer` value from the mark to the putIndex

    - #### sliceFromMark

          public Buffer sliceFromMark(int length)

      Specified by:
        `sliceFromMark` in interface `Buffer`
      Parameters:
        `length` - an `int` value
      Returns:
        a valitile `Buffer` value from the mark of the length requested.

    - #### space

          public int space()

      Description copied from interface: `Buffer`
      the space remaining in the buffer.
      Specified by:
        `space` in interface `Buffer`
      Returns:
        capacity - putIndex

    - #### toDetailString

          public String toDetailString()

      Specified by:
        `toDetailString` in interface `Buffer`
      Returns:
        a `String` value describing the state and contents of the buffer.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### toString

          public String toString(String charset)

      Specified by:
        `toString` in interface `Buffer`

    - #### toString

          public String toString(Charset charset)

      Specified by:
        `toString` in interface `Buffer`

    - #### toDebugString

          public String toDebugString()

    - #### writeTo

          public void writeTo(OutputStream out)
                       throws IOException

      Description copied from interface: `Buffer`
      Write the buffer's contents to the output stream
      Specified by:
        `writeTo` in interface `Buffer`
      Throws:
        `IOException`

    - #### readFrom

          public int readFrom(InputStream in,
                     int max)
                       throws IOException

      Description copied from interface: `Buffer`
      Read the buffer's contents from the input stream
      Specified by:
        `readFrom` in interface `Buffer`
      Parameters:
        `in` - input stream
        `max` - maximum number of bytes that may be read
      Returns:
        actual number of bytes read or -1 for EOF
      Throws:
        `IOException`

Copyright © 1995-2016 Mort Bay Consulting. All Rights Reserved.