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
public final class DataByteArrayOutputStream extends OutputStream implements DataOutput
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 byte[]getData()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()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)
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.
-
write
public void write(byte[] b, int off, int len)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.
-
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:
writeBooleanin interfaceDataOutput
-
writeByte
public void writeByte(int v)
- Specified by:
writeBytein interfaceDataOutput
-
writeShort
public void writeShort(int v)
- Specified by:
writeShortin interfaceDataOutput
-
writeChar
public void writeChar(int v)
- Specified by:
writeCharin interfaceDataOutput
-
writeInt
public void writeInt(int v)
- Specified by:
writeIntin interfaceDataOutput
-
writeLong
public void writeLong(long v)
- Specified by:
writeLongin interfaceDataOutput
-
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)
- Specified by:
writeBytesin interfaceDataOutput
-
writeChars
public void writeChars(String s)
- Specified by:
writeCharsin interfaceDataOutput
-
writeUTF
public void writeUTF(String text) throws IOException
- Specified by:
writeUTFin interfaceDataOutput- Throws:
IOException
-
-