Class DataByteArrayOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.activemq.store.kahadb.disk.util.DataByteArrayOutputStream
-
- All Implemented Interfaces:
Closeable,DataOutput,Flushable,AutoCloseable
public class DataByteArrayOutputStream extends OutputStream implements DataOutput, AutoCloseable
Optimized ByteArrayOutputStream
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteSequencegetByteSequence()byte[]getData()protected voidonWrite()This method is called after each write to the buffer.voidposition(int offset)Set the current position for writingvoidreset()reset the output streamvoidrestart()start using a fresh byte arrayvoidrestart(int size)start using a fresh byte arrayintsize()voidskip(int size)ByteSequencetoByteSequence()Get a ByteSequence from the streamvoidwrite(byte[] b, int off, int len)Writeslenbytes from the specified byte array starting at offsetoffto this byte array output stream.voidwrite(int b)Writes the specified byte to this byte array output stream.voidwriteBoolean(boolean v)voidwriteByte(int v)voidwriteBytes(String s)voidwriteChar(int v)voidwriteChars(String s)voidwriteDouble(double v)voidwriteFloat(float v)voidwriteInt(int v)voidwriteLong(long v)voidwriteShort(int v)voidwriteUTF(String text)-
Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream, 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
-
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 IOExceptionWrites the specified byte to this byte array output stream.- Specified by:
writein interfaceDataOutput- Specified by:
writein classOutputStream- Parameters:
b- the byte to be written.- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOExceptionWriteslenbytes from the specified byte array starting at offsetoffto this byte array output stream.- Specified by:
writein interfaceDataOutput- Overrides:
writein classOutputStream- 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 IOExceptionSet the current position for writing- Parameters:
offset-- Throws:
IOException
-
size
public int size()
-
writeBoolean
public void writeBoolean(boolean v) throws IOException- Specified by:
writeBooleanin interfaceDataOutput- Throws:
IOException
-
writeByte
public void writeByte(int v) throws IOException- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
writeShort
public void writeShort(int v) throws IOException- Specified by:
writeShortin interfaceDataOutput- Throws:
IOException
-
writeChar
public void writeChar(int v) throws IOException- Specified by:
writeCharin interfaceDataOutput- Throws:
IOException
-
writeInt
public void writeInt(int v) throws IOException- Specified by:
writeIntin interfaceDataOutput- Throws:
IOException
-
writeLong
public void writeLong(long v) throws IOException- Specified by:
writeLongin interfaceDataOutput- Throws:
IOException
-
writeFloat
public void writeFloat(float v) throws IOException- Specified by:
writeFloatin interfaceDataOutput- Throws:
IOException
-
writeDouble
public void writeDouble(double v) throws IOException- Specified by:
writeDoublein interfaceDataOutput- Throws:
IOException
-
writeBytes
public void writeBytes(String s) throws IOException
- Specified by:
writeBytesin interfaceDataOutput- Throws:
IOException
-
writeChars
public void writeChars(String s) throws IOException
- Specified by:
writeCharsin interfaceDataOutput- Throws:
IOException
-
writeUTF
public void writeUTF(String text) throws IOException
- Specified by:
writeUTFin interfaceDataOutput- Throws:
IOException
-
onWrite
protected void onWrite() throws IOExceptionThis 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()
-
-