org.webmacro.util
Class ByteBufferOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byorg.webmacro.util.ByteBufferOutputStream

public final class ByteBufferOutputStream
extends java.io.OutputStream


Constructor Summary
ByteBufferOutputStream(int size)
          Create a new ByteBuffer with the specified capacity
 
Method Summary
 void ensureCapacity(int len)
          Make sure the buffer contains space for len more bytes.
 byte[] getBuffer()
          Get the bytes in the buffer.
 byte[] getBytes()
          Allocate a new byte[] and fill it with the contents of the current byte buffer.
static void main(java.lang.String[] arg)
           
 void reset()
          Clear the contents of the byte buffer.
 int size()
          How many bytes currently in the buffer
 java.lang.String toString()
          Convert the bytes to a String using the default encoding
 java.lang.String toString(java.lang.String encoding)
          Convert the bytes to a String using the specified encodign
 void write(byte b)
          Append a single byte
 void write(byte[] b)
          Copy an array of bytes on to the end of the buffer
 void write(byte[] b, int offset, int len)
          Copy an array of bytes on to the end of the buffer
 void write(int i)
           
 void writeTo(java.io.OutputStream out)
          Write the bytes to the specified output stream
 
Methods inherited from class java.io.OutputStream
close, flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteBufferOutputStream

public ByteBufferOutputStream(int size)
Create a new ByteBuffer with the specified capacity

Method Detail

reset

public void reset()
Clear the contents of the byte buffer. Also shrinks the byte buffer to the size specified during construction of this ByteBufferOutputStream


write

public void write(int i)

write

public void write(byte[] b)
Copy an array of bytes on to the end of the buffer


write

public void write(byte[] b,
                  int offset,
                  int len)
Copy an array of bytes on to the end of the buffer


write

public void write(byte b)
Append a single byte


ensureCapacity

public final void ensureCapacity(int len)
Make sure the buffer contains space for len more bytes.


size

public int size()
How many bytes currently in the buffer


getBuffer

public byte[] getBuffer()
Get the bytes in the buffer. Note that you are getting the live buffer. You also need to call size() to find out how many of these bytes are significant. If you just want a byte array call getBytes() instead--that will allocate a new one for you.


getBytes

public byte[] getBytes()
Allocate a new byte[] and fill it with the contents of the current byte buffer. If you want the live byte buffer instead of this newly allocated copy call getBuffer() instead.


toString

public java.lang.String toString()
Convert the bytes to a String using the default encoding


toString

public java.lang.String toString(java.lang.String encoding)
                          throws java.io.UnsupportedEncodingException
Convert the bytes to a String using the specified encodign

Throws:
java.io.UnsupportedEncodingException

writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException
Write the bytes to the specified output stream

Throws:
java.io.IOException

main

public static void main(java.lang.String[] arg)