org.apache.activemq.store.kahadb.disk.util
Class DataByteArrayOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.apache.activemq.store.kahadb.disk.util.DataByteArrayOutputStream
All Implemented Interfaces:
Closeable, DataOutput, Flushable

public class DataByteArrayOutputStream
extends OutputStream
implements DataOutput

Optimized ByteArrayOutputStream


Field Summary
protected  byte[] buf
           
protected  int pos
           
 
Constructor Summary
DataByteArrayOutputStream()
          Creates a new byte array output stream.
DataByteArrayOutputStream(int size)
          Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
 
Method Summary
 ByteSequence getByteSequence()
           
 byte[] getData()
           
protected  void onWrite()
          This method is called after each write to the buffer.
 void position(int offset)
          Set the current position for writing
 void reset()
          reset the output stream
 void restart()
          start using a fresh byte array
 void restart(int size)
          start using a fresh byte array
 int size()
           
 void skip(int size)
           
 ByteSequence toByteSequence()
          Get a ByteSequence from the stream
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this byte array output stream.
 void write(int b)
          Writes the specified byte to this byte array output stream.
 void writeBoolean(boolean v)
           
 void writeByte(int v)
           
 void writeBytes(String s)
           
 void writeChar(int v)
           
 void writeChars(String s)
           
 void writeDouble(double v)
           
 void writeFloat(float v)
           
 void writeInt(int v)
           
 void writeLong(long v)
           
 void writeShort(int v)
           
 void writeUTF(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
 

Field Detail

buf

protected byte[] buf

pos

protected int pos
Constructor Detail

DataByteArrayOutputStream

public DataByteArrayOutputStream(int size)
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.

Parameters:
size - the initial size.
Throws:
IllegalArgumentException - if size is negative.

DataByteArrayOutputStream

public DataByteArrayOutputStream()
Creates a new byte array output stream.

Method Detail

restart

public void restart(int size)
start using a fresh byte array

Parameters:
size -

restart

public void restart()
start using a fresh byte array


toByteSequence

public ByteSequence toByteSequence()
Get a ByteSequence from the stream

Returns:
the byte sequence

write

public void write(int b)
           throws IOException
Writes the specified byte to this byte array output stream.

Specified by:
write in interface DataOutput
Specified by:
write in class OutputStream
Parameters:
b - the byte to be written.
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Writes len bytes from the specified byte array starting at offset off to this byte array output stream.

Specified by:
write in interface DataOutput
Overrides:
write in class OutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IOException

getData

public byte[] getData()
Returns:
the underlying byte[] buffer

reset

public void reset()
reset the output stream


position

public void position(int offset)
              throws IOException
Set the current position for writing

Parameters:
offset -
Throws:
IOException

size

public int size()

writeBoolean

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

writeByte

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

writeShort

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

writeChar

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

writeInt

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

writeLong

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

writeFloat

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

writeDouble

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

writeBytes

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

writeChars

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

writeUTF

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

onWrite

protected void onWrite()
                throws IOException
This method is called after each write to the buffer. This should allow subclasses to take some action based on the writes, for example flushing data to an external system based on size.

Throws:
IOException

skip

public void skip(int size)
          throws IOException
Throws:
IOException

getByteSequence

public ByteSequence getByteSequence()


Copyright © 2005–2013 The Apache Software Foundation. All rights reserved.