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.DataOutput
ImplementsDataOutput
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
Fields Modifier and Type Field Description protected byte[]
buf
protected boolean
grow_exponentially
protected int
pos
-
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 int
checkBounds(int pos)
protected void
ensureCapacity(int bytes)
Grows the buffer; whether it grow linearly or exponentially depends on grow_exponentiallyBuffer
getBuffer()
java.nio.ByteBuffer
getByteBuffer()
boolean
growExponentially()
ByteArrayDataOutputStream
growExponentially(boolean b)
int
position()
ByteArrayDataOutputStream
position(int pos)
java.lang.String
toString()
void
write(byte[] b)
void
write(byte[] b, int off, int len)
void
write(int b)
void
writeBoolean(boolean v)
void
writeByte(int v)
void
writeBytes(java.lang.String s)
void
writeChar(int v)
void
writeChars(java.lang.String s)
void
writeDouble(double v)
void
writeFloat(float v)
void
writeInt(int v)
void
writeLong(long v)
void
writeShort(int v)
void
writeUTF(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:
write
in interfacejava.io.DataOutput
-
write
public void write(byte[] b)
- Specified by:
write
in interfacejava.io.DataOutput
-
write
public void write(byte[] b, int off, int len)
- Specified by:
write
in interfacejava.io.DataOutput
-
writeBoolean
public void writeBoolean(boolean v)
- Specified by:
writeBoolean
in interfacejava.io.DataOutput
-
writeByte
public void writeByte(int v)
- Specified by:
writeByte
in interfacejava.io.DataOutput
-
writeShort
public void writeShort(int v)
- Specified by:
writeShort
in interfacejava.io.DataOutput
-
writeChar
public void writeChar(int v)
- Specified by:
writeChar
in interfacejava.io.DataOutput
-
writeInt
public void writeInt(int v)
- Specified by:
writeInt
in interfacejava.io.DataOutput
-
writeLong
public void writeLong(long v)
- Specified by:
writeLong
in interfacejava.io.DataOutput
-
writeFloat
public void writeFloat(float v)
- Specified by:
writeFloat
in interfacejava.io.DataOutput
-
writeDouble
public void writeDouble(double v)
- Specified by:
writeDouble
in interfacejava.io.DataOutput
-
writeBytes
public void writeBytes(java.lang.String s)
- Specified by:
writeBytes
in interfacejava.io.DataOutput
-
writeChars
public void writeChars(java.lang.String s)
- Specified by:
writeChars
in interfacejava.io.DataOutput
-
writeUTF
public void writeUTF(java.lang.String str)
- Specified by:
writeUTF
in interfacejava.io.DataOutput
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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
-
-