Class ByteArrayDataOutputStream
java.lang.Object
java.io.OutputStream
org.jgroups.util.BaseDataOutputStream
org.jgroups.util.ByteArrayDataOutputStream
- All Implemented Interfaces:
Closeable, DataOutput, Flushable, AutoCloseable
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
- Author:
- Bela Ban
-
Field Summary
FieldsFields inherited from class BaseDataOutputStream
grow_exponentially, pos -
Constructor Summary
ConstructorsConstructorDescriptionByteArrayDataOutputStream(int capacity) ByteArrayDataOutputStream(int capacity, boolean grow_exponentially) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]buffer()intcapacity()protected intcheckBounds(int pos) voidensureCapacity(int bytes) Grows the buffer; whether it grow linearly or exponentially depends on grow_exponentiallytoString()voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) voidwriteChar(int v) voidwriteInt(int v) voidwriteLong(long v) voidwriteShort(int v) Methods inherited from class BaseDataOutputStream
growExponentially, growExponentially, position, position, reset, writeBoolean, writeByte, writeBytes, writeChars, writeDouble, writeFloat, writeUTFMethods inherited from class OutputStream
close, flush, nullOutputStream
-
Field Details
-
buf
protected byte[] buf
-
-
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() -
writeChar
public void writeChar(int v) - Specified by:
writeCharin interfaceDataOutput- Overrides:
writeCharin classBaseDataOutputStream
-
writeInt
public void writeInt(int v) - Specified by:
writeIntin interfaceDataOutput- Overrides:
writeIntin classBaseDataOutputStream
-
writeLong
public void writeLong(long v) - Specified by:
writeLongin interfaceDataOutput- Overrides:
writeLongin classBaseDataOutputStream
-
writeShort
public void writeShort(int v) - Specified by:
writeShortin interfaceDataOutput- Overrides:
writeShortin classBaseDataOutputStream
-
write
public void write(int b) - Specified by:
writein interfaceDataOutput- Specified by:
writein classOutputStream
-
write
public void write(byte[] b) - Specified by:
writein interfaceDataOutput- Overrides:
writein classOutputStream
-
write
public void write(byte[] b, int off, int len) - Specified by:
writein interfaceDataOutput- Overrides:
writein classOutputStream
-
toString
- Overrides:
toStringin classBaseDataOutputStream
-
checkBounds
protected int checkBounds(int pos) - Overrides:
checkBoundsin classBaseDataOutputStream
-
ensureCapacity
public void ensureCapacity(int bytes) Grows the buffer; whether it grow linearly or exponentially depends on grow_exponentially- Specified by:
ensureCapacityin classBaseDataOutputStream
-