org.apache.asn1.ber.digester.rules
Class ByteAccumulator

java.lang.Object
  extended byorg.apache.asn1.ber.digester.rules.ByteAccumulator

public class ByteAccumulator
extends java.lang.Object

Gathers bytes from buffers while dynamically growing to accomodate a new size.

Version:
$Rev: 157644 $
Author:
Apache Directory Project

Field Summary
private  byte[] bs
          the accumulator's backing store
private static int DEFAULT_INCREMENT
          the default initial size
private static int DEFAULT_INIT_SIZE
          the default initial size
private  int increment
          the growth increment used to augment the backing store
private  int initial
          the initial size of the backing store
private  int pos
          the current position of the accumulator
 
Constructor Summary
  ByteAccumulator()
          Creates a ByteAccumulator used to gather bytes from various sources with a default initial size and a default growth increment.
(package private) ByteAccumulator(int initial)
          Creates a ByteAccumulator used to gather bytes from various sources with a default initial size and a default growth increment.
 
Method Summary
 java.nio.ByteBuffer drain()
          Wraps a ByteBuffer around the populated bytes of this ByteAccumulator and resets the backing store to a newly allocated byte array of initial size.
 java.nio.ByteBuffer drain(int initial)
          Wraps a ByteBuffer around the populated bytes of this ByteAccumulator and resets the backing store to a newly allocated byte array of initial size.
 void ensureCapacity(int capacity)
          Allocates memory to handle a capacity without the need to grow.
 void fill(java.nio.ByteBuffer buf)
          Fills this accumulator with the content of the argument buffer into this accumulator.
 int getCapacity()
          The current capacity of the backing store which may change as this accumulator is filled with bytes.
 int getGrowthIncrement()
          The growth increment by which the backing store is augmented.
 int getInitialSize()
          The initial size of the backing store.
 int getPosition()
          The current position within the backing store marking the point to which this accumulator is filled.
 int getRemainingSpace()
          The remaining free space that can be filled before having to grow the backing store of the accumulator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INIT_SIZE

private static final int DEFAULT_INIT_SIZE
the default initial size

See Also:
Constant Field Values

DEFAULT_INCREMENT

private static final int DEFAULT_INCREMENT
the default initial size

See Also:
Constant Field Values

bs

private byte[] bs
the accumulator's backing store


pos

private int pos
the current position of the accumulator


increment

private int increment
the growth increment used to augment the backing store


initial

private int initial
the initial size of the backing store

Constructor Detail

ByteAccumulator

public ByteAccumulator()
Creates a ByteAccumulator used to gather bytes from various sources with a default initial size and a default growth increment.


ByteAccumulator

ByteAccumulator(int initial)
Creates a ByteAccumulator used to gather bytes from various sources with a default initial size and a default growth increment.

Parameters:
initial - the initial size for the backing store
Method Detail

fill

public void fill(java.nio.ByteBuffer buf)
Fills this accumulator with the content of the argument buffer into this accumulator. The buffer argument is fully drained when this operation completes.

Parameters:
buf - the buffer to fill into this accumulator

drain

public java.nio.ByteBuffer drain()
Wraps a ByteBuffer around the populated bytes of this ByteAccumulator and resets the backing store to a newly allocated byte array of initial size.

Returns:
the compacted byte[] wrapped as a ByteBuffer

drain

public java.nio.ByteBuffer drain(int initial)
Wraps a ByteBuffer around the populated bytes of this ByteAccumulator and resets the backing store to a newly allocated byte array of initial size.

Returns:
the compacted byte[] wrapped as a ByteBuffer

ensureCapacity

public void ensureCapacity(int capacity)
Allocates memory to handle a capacity without the need to grow. This serves to control growth for more efficient use.

Parameters:
capacity - the capacity to hold without the need to grow

getGrowthIncrement

public int getGrowthIncrement()
The growth increment by which the backing store is augmented.

Returns:
the number of bytes to grow the backing store by

getInitialSize

public int getInitialSize()
The initial size of the backing store.

Returns:
the initial size in bytes of the backing store

getCapacity

public int getCapacity()
The current capacity of the backing store which may change as this accumulator is filled with bytes.

Returns:
the current capacity in bytes

getRemainingSpace

public int getRemainingSpace()
The remaining free space that can be filled before having to grow the backing store of the accumulator.

Returns:
the remaining free space until the next growth spurt

getPosition

public int getPosition()
The current position within the backing store marking the point to which this accumulator is filled.

Returns:
the current fill position


Copyright © 2004-2006 . All Rights Reserved.