Package org.apache.activemq.util
Class DataByteArrayOutputStream
java.lang.Object
java.io.OutputStream
org.apache.activemq.util.DataByteArrayOutputStream
- All Implemented Interfaces:
Closeable
,DataOutput
,Flushable
,AutoCloseable
Optimized ByteArrayOutputStream
-
Constructor Summary
ConstructorDescriptionCreates 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()
void
position
(int offset) Set the current position for writingvoid
reset()
reset the output streamvoid
restart()
start using a fresh byte arrayvoid
restart
(int size) start using a fresh byte arrayint
size()
Get a ByteSequence from the streamvoid
write
(byte[] b, int off, int len) Writeslen
bytes from the specified byte array starting at offsetoff
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
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 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
public void write(int b) Writes the specified byte to this byte array output stream.- Specified by:
write
in interfaceDataOutput
- Specified by:
write
in classOutputStream
- Parameters:
b
- the byte to be written.
-
write
public void write(byte[] b, int off, int len) Writeslen
bytes from the specified byte array starting at offsetoff
to this byte array output stream.- Specified by:
write
in interfaceDataOutput
- Overrides:
write
in classOutputStream
- Parameters:
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.
-
getData
public byte[] getData()- Returns:
- the underlying byte[] buffer
-
reset
public void reset()reset the output stream -
position
public void position(int offset) Set the current position for writing- Parameters:
offset
-
-
size
public int size() -
writeBoolean
public void writeBoolean(boolean v) - Specified by:
writeBoolean
in interfaceDataOutput
-
writeByte
public void writeByte(int v) - Specified by:
writeByte
in interfaceDataOutput
-
writeShort
public void writeShort(int v) - Specified by:
writeShort
in interfaceDataOutput
-
writeChar
public void writeChar(int v) - Specified by:
writeChar
in interfaceDataOutput
-
writeInt
public void writeInt(int v) - Specified by:
writeInt
in interfaceDataOutput
-
writeLong
public void writeLong(long v) - Specified by:
writeLong
in interfaceDataOutput
-
writeFloat
- Specified by:
writeFloat
in interfaceDataOutput
- Throws:
IOException
-
writeDouble
- Specified by:
writeDouble
in interfaceDataOutput
- Throws:
IOException
-
writeBytes
- Specified by:
writeBytes
in interfaceDataOutput
-
writeChars
- Specified by:
writeChars
in interfaceDataOutput
-
writeUTF
- Specified by:
writeUTF
in interfaceDataOutput
- Throws:
IOException
-