Package net.timewalker.ffmq4.utils
Class RawDataBuffer
- java.lang.Object
-
- net.timewalker.ffmq4.utils.RawDataBuffer
-
- All Implemented Interfaces:
DataInput,DataOutput
public final class RawDataBuffer extends Object implements DataOutput, DataInput
A RawDataBuffer is a dynamically growing byte array.
It implements
DataOutputandDataInputto 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 Summary
Constructors Constructor Description RawDataBuffer(byte[] initialBuffer)ConstructorRawDataBuffer(int initialCapacity)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()RawDataBuffercopy()Create a copy of this buffervoidensureCapacity(int targetCapacity)Ensure that the buffer internal capacity is at least targetCapacityvoidgetFrom(ByteBuffer byteBuffer, int offset, int len)intpos()voidputTo(ByteBuffer byteBuffer, int offset, int len)voidread(byte[] b)voidread(byte[] b, int off, int len)booleanreadBoolean()bytereadByte()bytereadByte(int position)Read a byte value at an arbitrary position in the bufferbyte[]readByteArray()Read a nullable byte array from the streambyte[]readBytes(int len)charreadChar()doublereadDouble()floatreadFloat()intreadFrom(InputStream in, int offset, int len)voidreadFully(byte[] b)voidreadFully(byte[] b, int off, int len)ObjectreadGeneric()Read a generic type from the streamintreadInt()StringreadLine()longreadLong()byte[]readNullableByteArray()Read a nullable byte array from the streamStringreadNullableUTF()Read a string or null value from the streamshortreadShort()intreadUnsignedByte()intreadUnsignedShort()StringreadUTF()voidreset()voidsetSize(int size)Set the buffer size (buffer is enlarged as necessary and padded with zeroes)intsize()intskipBytes(int n)byte[]toByteArray()byte[]toByteArray(int offset, int len)voidwrite(byte[] data)voidwrite(byte[] data, int offset, int len)voidwrite(int b)voidwriteBoolean(boolean v)voidwriteByte(byte v, int position)Write a byte value at an arbitrary position in the buffervoidwriteByte(int b)voidwriteByteArray(byte[] value)Write a nullable byte array to the streamvoidwriteBytes(String s)voidwriteChar(int v)voidwriteChars(String s)voidwriteDouble(double v)voidwriteFloat(float v)voidwriteGeneric(Object value)Write a generic type to the streamvoidwriteInt(int v)voidwriteInt(int v, int pos)Write a int value at an arbitrary position in the streamvoidwriteLong(long v)voidwriteNullableByteArray(byte[] value)Write a nullable byte array to the streamvoidwriteNullableUTF(String str)Write a string or null value to the streamvoidwriteShort(int v)voidwriteTo(OutputStream out)voidwriteTo(RawDataBuffer otherBuffer)voidwriteUTF(String str)
-
-
-
Method Detail
-
writeNullableUTF
public void writeNullableUTF(String str)
Write a string or null value to the stream
-
ensureCapacity
public final void ensureCapacity(int targetCapacity)
Ensure that the buffer internal capacity is at least targetCapacity- Parameters:
targetCapacity- the expected capacity
-
setSize
public void setSize(int size)
Set the buffer size (buffer is enlarged as necessary and padded with zeroes)- Parameters:
size-
-
write
public void write(int b)
- Specified by:
writein interfaceDataOutput
-
write
public void write(byte[] data)
- Specified by:
writein interfaceDataOutput
-
writeBytes
public void writeBytes(String s)
- Specified by:
writeBytesin interfaceDataOutput
-
writeChars
public void writeChars(String s)
- Specified by:
writeCharsin interfaceDataOutput
-
write
public void write(byte[] data, int offset, int len)- Specified by:
writein interfaceDataOutput
-
writeByte
public void writeByte(int b)
- Specified by:
writeBytein interfaceDataOutput
-
writeBoolean
public void writeBoolean(boolean v)
- Specified by:
writeBooleanin interfaceDataOutput
-
readByte
public byte readByte(int position)
Read a byte value at an arbitrary position in the buffer- Parameters:
position- the target position
-
writeByte
public void writeByte(byte v, int position)Write a byte value at an arbitrary position in the buffer- Parameters:
v- the byte valueposition- the target position
-
writeShort
public void writeShort(int v)
- Specified by:
writeShortin interfaceDataOutput
-
writeInt
public void writeInt(int v)
- Specified by:
writeIntin interfaceDataOutput
-
writeInt
public void writeInt(int v, int pos)Write a int value at an arbitrary position in the stream- Parameters:
v- the int valuepos- the target position
-
writeLong
public void writeLong(long v)
- Specified by:
writeLongin interfaceDataOutput
-
writeFloat
public void writeFloat(float v)
- Specified by:
writeFloatin interfaceDataOutput
-
writeDouble
public void writeDouble(double v)
- Specified by:
writeDoublein interfaceDataOutput
-
writeChar
public void writeChar(int v)
- Specified by:
writeCharin interfaceDataOutput
-
writeUTF
public void writeUTF(String str)
- Specified by:
writeUTFin interfaceDataOutput
-
writeNullableByteArray
public void writeNullableByteArray(byte[] value)
Write a nullable byte array to the stream
-
writeByteArray
public void writeByteArray(byte[] value)
Write a nullable byte array to the stream
-
writeGeneric
public void writeGeneric(Object value)
Write a generic type to the stream
-
readBoolean
public boolean readBoolean()
- Specified by:
readBooleanin interfaceDataInput
-
read
public void read(byte[] b)
-
read
public void read(byte[] b, int off, int len)
-
readBytes
public byte[] readBytes(int len)
-
readFully
public void readFully(byte[] b, int off, int len)
-
readUnsignedByte
public int readUnsignedByte()
- Specified by:
readUnsignedBytein interfaceDataInput
-
readUnsignedShort
public int readUnsignedShort()
- Specified by:
readUnsignedShortin interfaceDataInput
-
readDouble
public double readDouble()
- Specified by:
readDoublein interfaceDataInput
-
readNullableUTF
public String readNullableUTF()
Read a string or null value from the stream
-
readNullableByteArray
public byte[] readNullableByteArray()
Read a nullable byte array from the stream
-
readByteArray
public byte[] readByteArray()
Read a nullable byte array from the stream
-
readGeneric
public Object readGeneric()
Read a generic type from the stream
-
clear
public void clear()
-
reset
public void reset()
-
size
public int size()
-
pos
public int pos()
-
toByteArray
public byte[] toByteArray()
-
toByteArray
public byte[] toByteArray(int offset, int len)
-
writeTo
public void writeTo(OutputStream out) throws IOException
- Throws:
IOException
-
putTo
public void putTo(ByteBuffer byteBuffer, int offset, int len)
-
readFrom
public int readFrom(InputStream in, int offset, int len) throws IOException
- Throws:
IOException
-
getFrom
public void getFrom(ByteBuffer byteBuffer, int offset, int len)
-
writeTo
public void writeTo(RawDataBuffer otherBuffer)
-
copy
public RawDataBuffer copy()
Create a copy of this buffer- Returns:
- a copy of this buffer
-
-