com.github.libxjava.io
Class ByteArrayOutputBuffer

java.lang.Object
  extended by java.io.OutputStream
      extended by com.github.libxjava.io.ByteArrayOutputBuffer

public final class ByteArrayOutputBuffer
extends OutputStream

This implementation is like the ByteArrayOutputStream but not synchronised and it lets the user optimise byte array allocation. Furthermore this type of OutputStream is not closable, so it can be reused.

Version:
libxjava-cldc - 0.3
Author:
Marcel Patzlaff

Constructor Summary
ByteArrayOutputBuffer()
           
ByteArrayOutputBuffer(int size)
           
 
Method Summary
 void close()
          This type of outputstream is not closable.
 byte[] getByteArrayReference()
          Returns the reference to this buffer's byte array.
 void reset()
           
 void resetNew()
          Replaces the internal buffer with a new byte array of size 16.
 void resetNew(int size)
          Replaces the internal buffer with a new byte array of size size.
 void setOutput(byte[] buffer, int off)
          Resets the internal buffer with the specified byte array and initialises the internal write pointer to off.
 int size()
           
 byte[] toByteArray()
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayOutputBuffer

public ByteArrayOutputBuffer()

ByteArrayOutputBuffer

public ByteArrayOutputBuffer(int size)
Method Detail

getByteArrayReference

public byte[] getByteArrayReference()
Returns the reference to this buffer's byte array.

Remember that calling reset() only resets the internal counter. If you do not want any changes in the byte array obtained by this method, you need to call resetNew() or resetNew(int)!


toByteArray

public byte[] toByteArray()

reset

public void reset()

resetNew

public void resetNew()
Replaces the internal buffer with a new byte array of size 16. Call of this method equals resetNew(16)


resetNew

public void resetNew(int size)
Replaces the internal buffer with a new byte array of size size.

Parameters:
size -

setOutput

public void setOutput(byte[] buffer,
                      int off)
Resets the internal buffer with the specified byte array and initialises the internal write pointer to off.

Parameters:
buffer -
off -

size

public int size()

close

public void close()
This type of outputstream is not closable.

Overrides:
close in class OutputStream

write

public void write(byte[] b,
                  int off,
                  int len)
Overrides:
write in class OutputStream

write

public void write(int b)
Specified by:
write in class OutputStream


Copyright © 2011 Marcel Patzlaff. All Rights Reserved.