Package org.jgroups.util
Class ByteArrayDataOutputStream
- java.lang.Object
-
- org.jgroups.util.ByteArrayDataOutputStream
-
- All Implemented Interfaces:
java.io.DataOutput
public class ByteArrayDataOutputStream extends java.lang.Object implements java.io.DataOutputImplementsDataOutputover 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
Fields Modifier and Type Field Description protected byte[]bufprotected booleangrow_exponentiallyprotected intpos
-
Constructor Summary
Constructors Constructor Description ByteArrayDataOutputStream()ByteArrayDataOutputStream(int capacity)ByteArrayDataOutputStream(int capacity, boolean grow_exponentially)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]buffer()protected intcheckBounds(int pos)protected voidensureCapacity(int bytes)Grows the buffer; whether it grow linearly or exponentially depends on grow_exponentiallyBuffergetBuffer()java.nio.ByteBuffergetByteBuffer()booleangrowExponentially()ByteArrayDataOutputStreamgrowExponentially(boolean b)intposition()ByteArrayDataOutputStreamposition(int pos)java.lang.StringtoString()voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwriteBoolean(boolean v)voidwriteByte(int v)voidwriteBytes(java.lang.String s)voidwriteChar(int v)voidwriteChars(java.lang.String s)voidwriteDouble(double v)voidwriteFloat(float v)voidwriteInt(int v)voidwriteLong(long v)voidwriteShort(int v)voidwriteUTF(java.lang.String str)
-
-
-
Method Detail
-
position
public ByteArrayDataOutputStream position(int pos)
-
position
public int position()
-
buffer
public byte[] buffer()
-
getBuffer
public Buffer getBuffer()
-
getByteBuffer
public java.nio.ByteBuffer getByteBuffer()
-
growExponentially
public boolean growExponentially()
-
growExponentially
public ByteArrayDataOutputStream growExponentially(boolean b)
-
write
public void write(int b)
- Specified by:
writein interfacejava.io.DataOutput
-
write
public void write(byte[] b)
- Specified by:
writein interfacejava.io.DataOutput
-
write
public void write(byte[] b, int off, int len)- Specified by:
writein interfacejava.io.DataOutput
-
writeBoolean
public void writeBoolean(boolean v)
- Specified by:
writeBooleanin interfacejava.io.DataOutput
-
writeByte
public void writeByte(int v)
- Specified by:
writeBytein interfacejava.io.DataOutput
-
writeShort
public void writeShort(int v)
- Specified by:
writeShortin interfacejava.io.DataOutput
-
writeChar
public void writeChar(int v)
- Specified by:
writeCharin interfacejava.io.DataOutput
-
writeInt
public void writeInt(int v)
- Specified by:
writeIntin interfacejava.io.DataOutput
-
writeLong
public void writeLong(long v)
- Specified by:
writeLongin interfacejava.io.DataOutput
-
writeFloat
public void writeFloat(float v)
- Specified by:
writeFloatin interfacejava.io.DataOutput
-
writeDouble
public void writeDouble(double v)
- Specified by:
writeDoublein interfacejava.io.DataOutput
-
writeBytes
public void writeBytes(java.lang.String s)
- Specified by:
writeBytesin interfacejava.io.DataOutput
-
writeChars
public void writeChars(java.lang.String s)
- Specified by:
writeCharsin interfacejava.io.DataOutput
-
writeUTF
public void writeUTF(java.lang.String str)
- Specified by:
writeUTFin interfacejava.io.DataOutput
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
checkBounds
protected int checkBounds(int pos)
-
ensureCapacity
protected void ensureCapacity(int bytes)
Grows the buffer; whether it grow linearly or exponentially depends on grow_exponentially
-
-