org.vostok.io
Class ByteBuffer

java.lang.Object
  extended by org.vostok.io.ByteBuffer
All Implemented Interfaces:
java.io.Serializable

public class ByteBuffer
extends java.lang.Object
implements java.io.Serializable

ByteBuffer is an array of byte than can grow

Author:
levreau.jerome@vostoksystem.eu
See Also:
Serialized Form

Field Summary
static int HUGE
           
static int INSANE
           
static int MEDIUM
           
static int TINY
           
 
Constructor Summary
ByteBuffer()
          create a new ByteBuffer with a default growby of 1024
ByteBuffer(int growby)
          create a new ByteBuffer with a specific growing policy. use constant ou specify your own size (byte). bigger growby is, faster the buffer is but bigger the memory use is too.
 
Method Summary
 byte[] copy()
          return a newly allocated copy of the available data
 byte[] get()
          return a pointer on the current buffer. keep in mind that get().size !
 int getMaxSize()
          return the maximum data this buffer can (currently) hold without resizing
 int getSize()
          return the data size. this is the actual size, keep in mind that get().size !
 void push(byte b)
          push a byte on top of the buffer, increase buffer size if require
 void push(byte[] b)
          push bytes on top of the buffer, increase buffer size if require
 void push(byte[] b, int length)
          push bytes - up to size - on top of the buffer, increase buffer size if require
 void push(java.io.InputStream stream, int length)
          append data from stream, up to length byet to the Byte Buffer
 void truncate(int length)
          truncate data to size.
static ByteBuffer wrap(java.io.InputStream stream, int length)
          wrap an input stream into a ByteBuffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TINY

public static final int TINY
See Also:
Constant Field Values

MEDIUM

public static final int MEDIUM
See Also:
Constant Field Values

HUGE

public static final int HUGE
See Also:
Constant Field Values

INSANE

public static final int INSANE
See Also:
Constant Field Values
Constructor Detail

ByteBuffer

public ByteBuffer()
create a new ByteBuffer with a default growby of 1024


ByteBuffer

public ByteBuffer(int growby)
create a new ByteBuffer with a specific growing policy. use constant ou specify your own size (byte). bigger growby is, faster the buffer is but bigger the memory use is too.

Parameters:
growby -
Method Detail

wrap

public static ByteBuffer wrap(java.io.InputStream stream,
                              int length)
                       throws java.io.IOException
wrap an input stream into a ByteBuffer

Parameters:
stream - an input stream to load data from. buffer will start at the current stream position an up to size byte
length - maximun bytes to read. if set to -1, no limit
Returns:
Throws:
java.io.IOException
Since:
1.1

push

public void push(byte b)
push a byte on top of the buffer, increase buffer size if require

Parameters:
b -

push

public void push(byte[] b)
push bytes on top of the buffer, increase buffer size if require

Parameters:
b -

push

public void push(byte[] b,
                 int length)
push bytes - up to size - on top of the buffer, increase buffer size if require

Parameters:
b -

push

public void push(java.io.InputStream stream,
                 int length)
          throws java.io.IOException
append data from stream, up to length byet to the Byte Buffer

Parameters:
stream - an input stream to load data from. buffer will start at the current stream position an up to size byte
length - maximun bytes to read. if set to -1, no limit
Throws:
java.io.IOException
Since:
1.1

copy

public byte[] copy()
return a newly allocated copy of the available data

Returns:

get

public byte[] get()
return a pointer on the current buffer. keep in mind that get().size != getSize() changes made into the array will be repercuted into the buffer

Returns:

truncate

public void truncate(int length)
truncate data to size. This only alter the used data, NOT the actual size of the internal buffer, therefore still get().size != getSize()


getSize

public int getSize()
return the data size. this is the actual size, keep in mind that get().size != getSize()

Returns:

getMaxSize

public int getMaxSize()
return the maximum data this buffer can (currently) hold without resizing

Returns: