com.ejie.r01f.io
Class BytesOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended bycom.ejie.r01f.io.BytesOutputStream

public class BytesOutputStream
extends java.io.OutputStream

Versión des-sincronizada de ByteArrayOutputStream que ofrece una alternativa eficiente de SOLO LECTURA al array de bytes interno sin necesidad de hacer una copia (como es el caso de ByteArrayOutputStream), ver métodos writeTo y getInputStream


Constructor Summary
BytesOutputStream()
          Constructor por defecto
BytesOutputStream(int initialBufferSize)
          Inicialización a partir de un tamaño de buffer
 
Method Summary
 void close()
           
 int getLength()
          Devuelve el número de bytes que contiene el buffer interno
 void reset()
          Resetea el estado del buffer interno
 byte[] toByteArray()
          Devuelve una copia del buffer interno.
 java.io.InputStream toInputStream()
          Devuelve un InputStream que lee del buffer interno
 java.lang.String toString()
           
 void write(byte[] data, int offset, int length)
           
 void write(int datum)
           
 void writeTo(java.io.OutputStream out)
          Copia (vuelca) los datos del buffer interno en otro OutputStream
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BytesOutputStream

public BytesOutputStream()
Constructor por defecto


BytesOutputStream

public BytesOutputStream(int initialBufferSize)
Inicialización a partir de un tamaño de buffer

Parameters:
initialBufferSize - El tamaño inicial del buffer
Method Detail

write

public void write(int datum)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(byte[] data,
                  int offset,
                  int length)
           throws java.io.IOException
Throws:
java.io.IOException

close

public void close()

toByteArray

public byte[] toByteArray()
Devuelve una copia del buffer interno. OJO!!! Se trata de una COPIA NUEVA, no de una referencia al buffer interno

Returns:
El array de bytes con los datos del buffer

writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException
Copia (vuelca) los datos del buffer interno en otro OutputStream

Parameters:
out - El OutputStream al que hay que copiar (volcar) los datos
Throws:
java.io.IOException

toInputStream

public java.io.InputStream toInputStream()
Devuelve un InputStream que lee del buffer interno

Returns:

reset

public void reset()
           throws java.io.IOException
Resetea el estado del buffer interno

Throws:
java.io.IOException

getLength

public int getLength()
Devuelve el número de bytes que contiene el buffer interno

Returns:
El número de bytes que contiene el buffer.

toString

public java.lang.String toString()