public final class RawDataBuffer extends Object implements DataOutput, DataInput
A RawDataBuffer is a dynamically growing byte array.
It implements DataOutput and DataInput
to write or read data plus additional null-safe versions of the methods.
This class does not implement any synchronization nor bound checking
for maximum performance.
Note that the UTF read/write methods are not compatible with the JDK implementation
because they were modified to take advantage of the RawDataBuffer layout.
| Constructor and Description |
|---|
RawDataBuffer(byte[] initialBuffer)
Constructor
|
RawDataBuffer(int initialCapacity)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
RawDataBuffer |
copy()
Create a copy of this buffer
|
void |
ensureCapacity(int targetCapacity)
Ensure that the buffer internal capacity is at least targetCapacity
|
void |
getFrom(ByteBuffer byteBuffer,
int offset,
int len) |
int |
pos() |
void |
putTo(ByteBuffer byteBuffer,
int offset,
int len) |
void |
read(byte[] b) |
void |
read(byte[] b,
int off,
int len) |
boolean |
readBoolean() |
byte |
readByte() |
byte |
readByte(int position)
Read a byte value at an arbitrary position in the buffer
|
byte[] |
readByteArray()
Read a nullable byte array from the stream
|
byte[] |
readBytes(int len) |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
int |
readFrom(InputStream in,
int offset,
int len) |
void |
readFully(byte[] b) |
void |
readFully(byte[] b,
int off,
int len) |
Object |
readGeneric()
Read a generic type from the stream
|
int |
readInt() |
String |
readLine() |
long |
readLong() |
byte[] |
readNullableByteArray()
Read a nullable byte array from the stream
|
String |
readNullableUTF()
Read a string or null value from the stream
|
short |
readShort() |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
String |
readUTF() |
void |
reset() |
void |
setSize(int size)
Set the buffer size (buffer is enlarged as necessary and padded with zeroes)
|
int |
size() |
int |
skipBytes(int n) |
byte[] |
toByteArray() |
byte[] |
toByteArray(int offset,
int len) |
void |
write(byte[] data) |
void |
write(byte[] data,
int offset,
int len) |
void |
write(int b) |
void |
writeBoolean(boolean v) |
void |
writeByte(byte v,
int position)
Write a byte value at an arbitrary position in the buffer
|
void |
writeByte(int b) |
void |
writeByteArray(byte[] value)
Write a nullable byte array to the stream
|
void |
writeBytes(String s) |
void |
writeChar(int v) |
void |
writeChars(String s) |
void |
writeDouble(double v) |
void |
writeFloat(float v) |
void |
writeGeneric(Object value)
Write a generic type to the stream
|
void |
writeInt(int v) |
void |
writeInt(int v,
int pos)
Write a int value at an arbitrary position in the stream
|
void |
writeLong(long v) |
void |
writeNullableByteArray(byte[] value)
Write a nullable byte array to the stream
|
void |
writeNullableUTF(String str)
Write a string or null value to the stream
|
void |
writeShort(int v) |
void |
writeTo(OutputStream out) |
void |
writeTo(RawDataBuffer otherBuffer) |
void |
writeUTF(String str) |
public RawDataBuffer(int initialCapacity)
initialCapacity - initial buffer capacitypublic RawDataBuffer(byte[] initialBuffer)
initialBuffer - the initial buffer to use internallypublic void writeNullableUTF(String str)
public final void ensureCapacity(int targetCapacity)
targetCapacity - the expected capacitypublic void setSize(int size)
size - public void write(int b)
write in interface DataOutputpublic void write(byte[] data)
write in interface DataOutputpublic void writeBytes(String s)
writeBytes in interface DataOutputpublic void writeChars(String s)
writeChars in interface DataOutputpublic void write(byte[] data,
int offset,
int len)
write in interface DataOutputpublic void writeByte(int b)
writeByte in interface DataOutputpublic void writeBoolean(boolean v)
writeBoolean in interface DataOutputpublic byte readByte(int position)
position - the target positionpublic void writeByte(byte v,
int position)
v - the byte valueposition - the target positionpublic void writeShort(int v)
writeShort in interface DataOutputpublic void writeInt(int v)
writeInt in interface DataOutputpublic void writeInt(int v,
int pos)
v - the int valuepos - the target positionpublic void writeLong(long v)
writeLong in interface DataOutputpublic void writeFloat(float v)
writeFloat in interface DataOutputpublic void writeDouble(double v)
writeDouble in interface DataOutputpublic void writeChar(int v)
writeChar in interface DataOutputpublic void writeUTF(String str)
writeUTF in interface DataOutputpublic void writeNullableByteArray(byte[] value)
public void writeByteArray(byte[] value)
public void writeGeneric(Object value)
public boolean readBoolean()
readBoolean in interface DataInputpublic void read(byte[] b)
public void read(byte[] b,
int off,
int len)
public byte[] readBytes(int len)
public void readFully(byte[] b,
int off,
int len)
public int readUnsignedByte()
readUnsignedByte in interface DataInputpublic int readUnsignedShort()
readUnsignedShort in interface DataInputpublic double readDouble()
readDouble in interface DataInputpublic String readNullableUTF()
public byte[] readNullableByteArray()
public byte[] readByteArray()
public Object readGeneric()
public void clear()
public void reset()
public int size()
public int pos()
public byte[] toByteArray()
public byte[] toByteArray(int offset,
int len)
public void writeTo(OutputStream out) throws IOException
IOExceptionpublic void putTo(ByteBuffer byteBuffer, int offset, int len)
public int readFrom(InputStream in, int offset, int len) throws IOException
IOExceptionpublic void getFrom(ByteBuffer byteBuffer, int offset, int len)
public void writeTo(RawDataBuffer otherBuffer)
public RawDataBuffer copy()
Copyright © 2021. All rights reserved.