Novell exteNd
Director 5.2 API

com.sssw.fw.util
Class EboByteBuffer

java.lang.Object
 |
 +--com.sssw.fw.util.EboByteBuffer

public class EboByteBuffer
extends Object

EboByteBuffer is a wrapper class around a byte array. A ByteBuffer API allows reads and writes without worrying about underlying byte array. This class is intended to be used as the underlying storage mechanism for pair(s) of Input/Output Stream classes that can attach/detach its underlying storage facility.. Please note, this class is not synchronized. It is up to the user of this storage facility to handle synchronization. This is a com.sssw.test.test reimplementation that uses a linked list of byte array chunks, rather than a single buffer that is copied. This is an attempt to get a couple of orders of magnitude performance improvement.


Constructor Summary
EboByteBuffer()
          Creates a EboByteBuffer with the default byte array size and chunk count
EboByteBuffer(byte[] buf)
          Creates a EboByteBuffer from the specified array of bytes.
EboByteBuffer(InputStream in)
          No information available
EboByteBuffer(InputStream in, int incr)
          Creates a EboByteBuffer from the contents of the specified InputStream.
EboByteBuffer(int size)
          Creates a EboByteBuffer with the specified byte array size Will also grow by this size.
EboByteBuffer(String str)
          Deprecated.  
EboByteBuffer(String str, String enc)
          Creates an EboByteBuffer from the specified string using the specified encoding.
 
Method Summary
 int available()
          Get the size of the available buffer space.
protected  byte[] getBuffer()
          Get the actual storage array N.B.
 int getPosition()
          Return the current position.
 int read()
          Read the next byte from the buffer.
 int read(byte[] buf, int offset, int len)
          Read a stream of bytes until the specified output array is full.
 void reset()
          Re-set the buffer to the empty state.
 void resetPos()
          Reset the cursor to start of buffer for reading
 boolean seek(int desiredPosition)
          Move the cursor position.
 int size()
          Get the current size of the buffer that is in use.
 long skip(long skipCnt)
          Move the cursor position forward by specified number of bytes.
 byte[] toByteArray()
          Get a copy of the in use portion of the buffer as a byte array
 String toString()
          Get the byte array as a String, using the default platform encoding.
 String toString(String enc)
          Get the byte array as a String, using the specified encoding.
 void write(byte[] bytes, int offset, int len)
          Write the specified number of bytes to the buffer.
 void write(int b)
          Write the specified byte to the buffer.
 void writeTo(OutputStream out)
          Writes the complete contents of this byte buffer to the specified output stream argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EboByteBuffer

public EboByteBuffer()
Creates a EboByteBuffer with the default byte array size and chunk count

EboByteBuffer

public EboByteBuffer(int size)
Creates a EboByteBuffer with the specified byte array size Will also grow by this size.
Parameters:
size - the initial buffer size

EboByteBuffer

public EboByteBuffer(byte[] buf)
Creates a EboByteBuffer from the specified array of bytes. The specified buffer is not copied, but is used in place!! This constructor also assumes that the byte array is fully inuse!!
Parameters:
buf - the input buffer (not copied)

EboByteBuffer

public EboByteBuffer(String str)
Deprecated.  

No information available

EboByteBuffer

public EboByteBuffer(String str,
                     String enc)
              throws UnsupportedEncodingException
Creates an EboByteBuffer from the specified string using the specified encoding.
Parameters:
str - The string to store
enc - The charset encoding to use
Throws:
UnsupportedEncodingException -  

EboByteBuffer

public EboByteBuffer(InputStream in,
                     int incr)
              throws com.sssw.fw.util.IOException
Creates a EboByteBuffer from the contents of the specified InputStream.
Parameters:
in - The InputStream used to initialize the ByteBuffer
incr - An int increment size to grow buffer when needed

EboByteBuffer

public EboByteBuffer(InputStream in)
              throws com.sssw.fw.util.IOException
No information available
Method Detail

resetPos

public void resetPos()
Reset the cursor to start of buffer for reading

toByteArray

public byte[] toByteArray()
Get a copy of the in use portion of the buffer as a byte array
Returns:
byte array containing a copy of the buffer

toString

public String toString()
Get the byte array as a String, using the default platform encoding.
Overrides:
toString in class Object
Returns:
String value of byte array

toString

public String toString(String enc)
                throws UnsupportedEncodingException
Get the byte array as a String, using the specified encoding.
Parameters:
enc - The encoding name of the encoding to use.
Returns:
String value of byte array

available

public int available()
Get the size of the available buffer space.
Returns:
the number of bytes that can be read without blocking

size

public int size()
Get the current size of the buffer that is in use.
Returns:
the size of the buffer currently in use

reset

public void reset()
Re-set the buffer to the empty state.

getBuffer

protected byte[] getBuffer()
Get the actual storage array N.B. this is now an expensive operation because it copies the buffer!

read

public int read()
Read the next byte from the buffer.
Returns:
next byte value or -1 if at end of buffer

read

public int read(byte[] buf,
                int offset,
                int len)
Read a stream of bytes until the specified output array is full.
Parameters:
buf - output byte array
offset - starting index to use in the output array
len - the number of bytes to read
Returns:
number of bytes actually read or -1 if end of buffer is reached.

skip

public long skip(long skipCnt)
Move the cursor position forward by specified number of bytes.
Parameters:
skipCnt - requested number of bytes to skip
Returns:
actual number of bytes skipped

seek

public final boolean seek(int desiredPosition)
Move the cursor position.
Parameters:
position - requested position.
Returns:
true if position valid and false if out of range.

getPosition

public final int getPosition()
Return the current position.
Returns:
current position.

write

public void write(int b)
Write the specified byte to the buffer.
Parameters:
b - the byte to write to buffer

write

public void write(byte[] bytes,
                  int offset,
                  int len)
Write the specified number of bytes to the buffer.
Parameters:
b - byte array containing bytes to be written to buffer
offset - starting offset in the input byte array to use
len - number of bytes to be written

writeTo

public void writeTo(OutputStream out)
             throws com.sssw.fw.util.IOException
Writes the complete contents of this byte buffer to the specified output stream argument.
Parameters:
out - the output stream byte to write to.

Novell exteNd
Director 5.2 API