Class DataByteArrayOutputStream
java.lang.Object
java.io.OutputStream
org.fusesource.hawtbuf.DataByteArrayOutputStream
- All Implemented Interfaces:
Closeable, DataOutput, Flushable, AutoCloseable
Optimized ByteArrayOutputStream
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]private static final intprotected AbstractVarIntSupportprotected int -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new byte array output stream.DataByteArrayOutputStream(byte[] buf) DataByteArrayOutputStream(int size) Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidensureEnoughBuffer(int newcount) byte[]getData()protected voidonWrite()This method is called after each write to the buffer.intposition()voidposition(int offset) Set the current position for writingvoidreset()reset the output streamprotected voidresize(int newcount) voidrestart()start using a fresh byte arrayvoidrestart(int size) start using a fresh byte arrayintsize()voidskip(int size) toBuffer()Get a Buffer 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.voidvoidwriteBoolean(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) voidvoidwriteVarInt(int value) voidwriteVarLong(long value) voidwriteVarSignedInt(int value) voidwriteVarSignedLong(long value) Methods inherited from class OutputStream
close, flush, writeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DataOutput
write
-
Field Details
-
DEFAULT_SIZE
private static final int DEFAULT_SIZE- See Also:
-
buf
protected byte[] buf -
pos
protected int pos -
helper
-
-
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(byte[] buf) -
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 -
toBuffer
-
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
- 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
-
position
public int position() -
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
-
ensureEnoughBuffer
private void ensureEnoughBuffer(int newcount) -
resize
protected void resize(int newcount) -
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
-
writeVarInt
- Throws:
IOException
-
writeVarLong
- Throws:
IOException
-
writeVarSignedInt
- Throws:
IOException
-
writeVarSignedLong
- Throws:
IOException
-