org.apache.mina.util.byteaccess

## Class CompositeByteArrayRelativeWriter

- java.lang.Object
- - org.apache.mina.util.byteaccess.CompositeByteArrayRelativeWriter

- All Implemented Interfaces:
    IoRelativeWriter

      public class CompositeByteArrayRelativeWriter
      extends Object
      implements IoRelativeWriter

  Provides restricted, relative, write-only access to the bytes in a `CompositeByteArray`. Using this interface has the advantage that it can be automatically determined when a component `ByteArray` can no longer be written to, and thus components can be automatically flushed. This makes it easier to use pooling for underlying `ByteArray`s. By providing an appropriate `Expander` it is also possible to automatically add more backing storage as more data is written.
  TODO: Get flushing working.
  Author:
    Apache MINA Project

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `CompositeByteArrayRelativeWriter.ChunkedExpander` Expands the supplied `CompositeByteArray` by the number of bytes provided in the constructor
    `static interface` | `CompositeByteArrayRelativeWriter.Expander` An object that knows how to expand a `CompositeByteArray`.
    `static interface` | `CompositeByteArrayRelativeWriter.Flusher` An object that knows how to flush a `ByteArray`.
    `static class` | `CompositeByteArrayRelativeWriter.NopExpander` No-op expander.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected CompositeByteArray` | `cba` The underlying `CompositeByteArray`.
    `protected ByteArray.Cursor` | `cursor` A cursor of the underlying `CompositeByteArray`.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CompositeByteArrayRelativeWriter(CompositeByteArray cba, CompositeByteArrayRelativeWriter.Expander expander, CompositeByteArrayRelativeWriter.Flusher flusher, boolean autoFlush)` Creates a new instance of CompositeByteArrayRelativeWriter.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `append(ByteArray ba)` Make a `ByteArray` available for access at the end of this object.
    `protected void` | `cursorPassedFirstComponent()` Called whenever the cursor has passed from the `cba`'s first component.
    `void` | `flush()` Flush to the current index.
    `void` | `flushTo(int index)` Flush to the given index.
    `void` | `free()` Free all resources associated with this object.
    `int` | `getIndex()` Get the index that will be used for the next access.
    `int` | `getRemaining()`
    `boolean` | `hasRemaining()`
    `int` | `last()` Get the index after the last byte that can be accessed.
    `ByteOrder` | `order()`
    `void` | `put(byte b)` Puts a `byte` and advances the reader.
    `void` | `put(IoBuffer bb)` Puts enough bytes to fill the `IoBuffer` and advances the reader.
    `void` | `putChar(char c)` Puts a `char` and advances the reader.
    `void` | `putDouble(double d)` Puts a `double` and advances the reader.
    `void` | `putFloat(float f)` Puts a `float` and advances the reader.
    `void` | `putInt(int i)` Puts an `int` and advances the reader.
    `void` | `putLong(long l)` Puts a `long` and advances the reader.
    `void` | `putShort(short s)` Puts a `short` and advances the reader.
    `void` | `skip(int length)` Advances the writer by the given number of bytes.

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.mina.util.byteaccess.IoRelativeWriter

      `getRemaining, hasRemaining, order`

- - ### Field Detail

    - #### cba

          protected final CompositeByteArray cba

      The underlying `CompositeByteArray`.

    - #### cursor

          protected final ByteArray.Cursor cursor

      A cursor of the underlying `CompositeByteArray`. This cursor is never moved directly; its position only changes through calls to relative read or write methods.

  - ### Constructor Detail

    - #### CompositeByteArrayRelativeWriter

          public CompositeByteArrayRelativeWriter(CompositeByteArray cba,
                                          CompositeByteArrayRelativeWriter.Expander expander,
                                          CompositeByteArrayRelativeWriter.Flusher flusher,
                                          boolean autoFlush)

      Creates a new instance of CompositeByteArrayRelativeWriter.
      Parameters:
        `cba` - The CompositeByteArray to use to back this class
        `expander` - The expander. Will increase the size of the internal ByteArray
        `flusher` - Flushed the ByteArray when necessary
        `autoFlush` - Should this class automatically flush?

  - ### Method Detail

    - #### flush

          public void flush()

      Flush to the current index.

    - #### flushTo

          public void flushTo(int index)

      Flush to the given index.

    - #### skip

          public void skip(int length)

      Description copied from interface: `IoRelativeWriter`
      Advances the writer by the given number of bytes.
      Specified by:
        `skip` in interface `IoRelativeWriter`

    - #### cursorPassedFirstComponent

          protected void cursorPassedFirstComponent()

      Called whenever the cursor has passed from the `cba`'s first component. As the first component is no longer used, this provides a good opportunity for subclasses to perform some action on it (such as freeing it).

    - #### put

          public void put(byte b)

      Description copied from interface: `IoRelativeWriter`
      Puts a `byte` and advances the reader.
      Specified by:
        `put` in interface `IoRelativeWriter`

    - #### put

          public void put(IoBuffer bb)

      Description copied from interface: `IoRelativeWriter`
      Puts enough bytes to fill the `IoBuffer` and advances the reader.
      Specified by:
        `put` in interface `IoRelativeWriter`

    - #### putShort

          public void putShort(short s)

      Description copied from interface: `IoRelativeWriter`
      Puts a `short` and advances the reader.
      Specified by:
        `putShort` in interface `IoRelativeWriter`

    - #### putInt

          public void putInt(int i)

      Description copied from interface: `IoRelativeWriter`
      Puts an `int` and advances the reader.
      Specified by:
        `putInt` in interface `IoRelativeWriter`

    - #### putLong

          public void putLong(long l)

      Description copied from interface: `IoRelativeWriter`
      Puts a `long` and advances the reader.
      Specified by:
        `putLong` in interface `IoRelativeWriter`

    - #### putFloat

          public void putFloat(float f)

      Description copied from interface: `IoRelativeWriter`
      Puts a `float` and advances the reader.
      Specified by:
        `putFloat` in interface `IoRelativeWriter`

    - #### putDouble

          public void putDouble(double d)

      Description copied from interface: `IoRelativeWriter`
      Puts a `double` and advances the reader.
      Specified by:
        `putDouble` in interface `IoRelativeWriter`

    - #### putChar

          public void putChar(char c)

      Description copied from interface: `IoRelativeWriter`
      Puts a `char` and advances the reader.
      Specified by:
        `putChar` in interface `IoRelativeWriter`

    - #### getRemaining

          public final int getRemaining()

    - #### hasRemaining

          public final boolean hasRemaining()

    - #### order

          public ByteOrder order()

    - #### append

          public final void append(ByteArray ba)

      Make a `ByteArray` available for access at the end of this object.

    - #### free

          public final void free()

      Free all resources associated with this object.

    - #### getIndex

          public final int getIndex()

      Get the index that will be used for the next access.

    - #### last

          public final int last()

      Get the index after the last byte that can be accessed.

Copyright © 2004-2012 Apache MINA Project. All Rights Reserved.