Package org.jgroups.util
Class ByteArrayDataOutputStream
java.lang.Object
org.jgroups.util.BaseDataOutputStream
org.jgroups.util.ByteArrayDataOutputStream
- All Implemented Interfaces:
DataOutput
Implements
DataOutput over a byte[] buffer. The byte[] buffer expands when needed; however, it
doesn't double but only expands minimally, to accommodate the additional data.
It is therefore recommended to always size the buffer to the actual number of bytes needed.
This class is not thread safe.- Since:
- 3.5
-
Field Summary
FieldsFields inherited from class org.jgroups.util.BaseDataOutputStream
pos -
Constructor Summary
ConstructorsConstructorDescriptionByteArrayDataOutputStream(int capacity) ByteArrayDataOutputStream(int capacity, boolean grow_exponentially) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]buffer()intcapacity()protected intcheckBounds(int pos) protected voidensureCapacity(int bytes) Grows the buffer; whether it grow linearly or exponentially depends on grow_exponentiallybooleangrowExponentially(boolean b) toString()voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) Methods inherited from class org.jgroups.util.BaseDataOutputStream
position, position, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
Field Details
-
buf
protected byte[] buf -
grow_exponentially
protected boolean grow_exponentially
-
-
Constructor Details
-
ByteArrayDataOutputStream
public ByteArrayDataOutputStream() -
ByteArrayDataOutputStream
public ByteArrayDataOutputStream(int capacity) -
ByteArrayDataOutputStream
public ByteArrayDataOutputStream(int capacity, boolean grow_exponentially)
-
-
Method Details
-
buffer
public byte[] buffer() -
getBuffer
-
byteBuffer
-
capacity
public int capacity() -
growExponentially
public boolean growExponentially() -
growExponentially
-
write
public void write(int b) - Specified by:
writein interfaceDataOutput- Specified by:
writein classBaseDataOutputStream
-
write
public void write(byte[] b) - Specified by:
writein interfaceDataOutput- Overrides:
writein classBaseDataOutputStream
-
write
public void write(byte[] b, int off, int len) - Specified by:
writein interfaceDataOutput- Specified by:
writein classBaseDataOutputStream
-
toString
- Overrides:
toStringin classBaseDataOutputStream
-
checkBounds
protected int checkBounds(int pos) - Overrides:
checkBoundsin classBaseDataOutputStream
-
ensureCapacity
protected void ensureCapacity(int bytes) Grows the buffer; whether it grow linearly or exponentially depends on grow_exponentially- Specified by:
ensureCapacityin classBaseDataOutputStream
-