Class DataByteArrayOutputStream
java.lang.Object
java.io.OutputStream
org.apache.activemq.store.kahadb.disk.util.DataByteArrayOutputStream
- All Implemented Interfaces:
Closeable,DataOutput,Flushable,AutoCloseable
Optimized ByteArrayOutputStream
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionbyte[]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) 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) voidMethods inherited from class java.io.OutputStream
close, flush, nullOutputStream, writeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.io.DataOutput
write
-
Field Details
-
buf
protected byte[] buf -
pos
protected int pos
-
-
Constructor Details
-
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 Details
-
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
Get a ByteSequence from the stream- Returns:
- the byte sequence
-
write
Writes 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
Writeslenbytes 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
Set the current position for writing- Parameters:
offset-- Throws:
IOException
-
size
public int size() -
writeBoolean
- Specified by:
writeBooleanin interfaceDataOutput- Throws:
IOException
-
writeByte
- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
writeShort
- Specified by:
writeShortin interfaceDataOutput- Throws:
IOException
-
writeChar
- Specified by:
writeCharin interfaceDataOutput- Throws:
IOException
-
writeInt
- Specified by:
writeIntin interfaceDataOutput- Throws:
IOException
-
writeLong
- Specified by:
writeLongin interfaceDataOutput- Throws:
IOException
-
writeFloat
- Specified by:
writeFloatin interfaceDataOutput- Throws:
IOException
-
writeDouble
- Specified by:
writeDoublein interfaceDataOutput- Throws:
IOException
-
writeBytes
- Specified by:
writeBytesin interfaceDataOutput- Throws:
IOException
-
writeChars
- Specified by:
writeCharsin interfaceDataOutput- Throws:
IOException
-
writeUTF
- Specified by:
writeUTFin interfaceDataOutput- Throws:
IOException
-
onWrite
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
- Throws:
IOException
-
getByteSequence
-