com.smaxe.io
Class ByteArrayOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.smaxe.io.ByteArrayOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.DataOutput, java.io.Flushable

public final class ByteArrayOutputStream
extends java.io.OutputStream
implements java.io.DataOutput

ByteArrayOutputStream - OutputStream implementation based on ByteArray.

Note: The implementation is:
- not thread-safe.
- 1.1 compatible
- DataOutput implementation is AMF0(3) compatible (rather than DataOutputStream).

Author:
Andrei Sochirca

Constructor Summary
ByteArrayOutputStream(byte[] buf)
          Constructor.
ByteArrayOutputStream(byte[] buf, int offset)
          Constructor.
ByteArrayOutputStream(ByteArray buf)
          Constructor.
 
Method Summary
 ByteArray getArray()
           
 int getWritten()
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeBoolean(boolean v)
           
 void writeByte(int v)
           
 void writeBytes(java.lang.String s)
           
 void writeChar(int v)
           
 void writeChars(java.lang.String s)
           
static void writeContent(ByteArrayOutputStream os, IContentProvider contentProvider)
          Writes content with content 4-bytes 'length' prefix, i.e.
 void writeDouble(double v)
           
 void writeFloat(float v)
           
 void writeInt(int v)
           
 void writeLong(long v)
           
 void writeShort(int v)
           
 void writeUTF(java.lang.String str)
           
 
Methods inherited from class java.io.OutputStream
close, flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.DataOutput
write
 

Constructor Detail

ByteArrayOutputStream

public ByteArrayOutputStream(byte[] buf)
Constructor.

Parameters:
buf -

ByteArrayOutputStream

public ByteArrayOutputStream(byte[] buf,
                             int offset)
Constructor.

Parameters:
buf -
offset -

ByteArrayOutputStream

public ByteArrayOutputStream(ByteArray buf)
Constructor.

Parameters:
buf -
Method Detail

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in interface java.io.DataOutput
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Specified by:
write in interface java.io.DataOutput
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

writeBoolean

public void writeBoolean(boolean v)
                  throws java.io.IOException
Specified by:
writeBoolean in interface java.io.DataOutput
Throws:
java.io.IOException

writeByte

public void writeByte(int v)
               throws java.io.IOException
Specified by:
writeByte in interface java.io.DataOutput
Throws:
java.io.IOException

writeBytes

public void writeBytes(java.lang.String s)
                throws java.io.IOException
Specified by:
writeBytes in interface java.io.DataOutput
Throws:
java.io.IOException

writeChar

public void writeChar(int v)
               throws java.io.IOException
Specified by:
writeChar in interface java.io.DataOutput
Throws:
java.io.IOException

writeChars

public void writeChars(java.lang.String s)
                throws java.io.IOException
Specified by:
writeChars in interface java.io.DataOutput
Throws:
java.io.IOException

writeDouble

public void writeDouble(double v)
                 throws java.io.IOException
Specified by:
writeDouble in interface java.io.DataOutput
Throws:
java.io.IOException

writeFloat

public void writeFloat(float v)
                throws java.io.IOException
Specified by:
writeFloat in interface java.io.DataOutput
Throws:
java.io.IOException

writeInt

public void writeInt(int v)
              throws java.io.IOException
Specified by:
writeInt in interface java.io.DataOutput
Throws:
java.io.IOException

writeLong

public void writeLong(long v)
               throws java.io.IOException
Specified by:
writeLong in interface java.io.DataOutput
Throws:
java.io.IOException

writeShort

public void writeShort(int v)
                throws java.io.IOException
Specified by:
writeShort in interface java.io.DataOutput
Throws:
java.io.IOException

writeUTF

public void writeUTF(java.lang.String str)
              throws java.io.IOException
Specified by:
writeUTF in interface java.io.DataOutput
Throws:
java.io.IOException

getArray

public final ByteArray getArray()
Returns:
buffer

getWritten

public final int getWritten()
Returns:
number of written bytes

writeContent

public static void writeContent(ByteArrayOutputStream os,
                                IContentProvider contentProvider)
                         throws java.io.IOException
Writes content with content 4-bytes 'length' prefix, i.e. [content-length][content] is written to the os.

Parameters:
os -
contentProvider -
Throws:
java.io.IOException - if an I/O exception occurred