Package septogeddon.pluginquery.utils
Class DataBuffer
java.lang.Object
septogeddon.pluginquery.utils.DataBuffer
- All Implemented Interfaces:
DataInput,DataOutput
- Direct Known Subclasses:
ObjectBuffer
DataBuffer for PluginQuery. Hold objects in byte buffer to send later or read later.
- Author:
- Thito Yalasatria Sunarya
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate a buffer with 32 byte length of initial sizeDataBuffer(byte[] buff) Create a buffer with existing byte arrayDataBuffer(int initialSize) Create a buffer with specific initial sizeDataBuffer(InputStream input) Read the input stream and copy it to the buffer -
Method Summary
Modifier and TypeMethodDescriptionintGet readable bytes (basically the current buffer size)voidclear()Clear the buffervoidcopyTo(OutputStream output) Copy the buffer to the OutputStreamvoidfinalize()Flush the byte arrayintread()Read a byteintread(byte[] bytes) Read and fill the provided byte arrayintread(byte[] b, int off, int len) Read bytes at specific offset and lengthfinal booleanRead a booleanfinal bytereadByte()Read a byteRead a string (non charset)final charreadChar()Read a characterRead a string (using charset)final doubleRead a doublefinal floatRead a floatfinal voidreadFully(byte[] b) Read and fill the provided byte arrayfinal voidreadFully(byte[] b, int off, int len) Read and fill the provided byte array at specific offset and lengthfinal intreadInt()Read an integerfinal StringreadLine()Deprecated.final longreadLong()Read a longfinal shortRead a shortfinal intRead an unsigned bytefinal intRead an unsigned shortfinal StringreadUTF()Read a String (UTF)longskip(long n) Skip bytesfinal intskipBytes(int n) Skip bytesbyte[]Transform this buffer into a byte arrayvoidwrite(byte[] b) Write byte array to this buffervoidwrite(byte[] b, int off, int len) Write byte array at specific offset and length to this buffervoidwrite(int b) Write a byte to this bufferfinal voidwriteBoolean(boolean v) Write a boolean to this bufferfinal voidwriteByte(int v) Write a byte to this bufferfinal voidwriteBytes(String s) Write a String (non Charset)final voidwriteChar(int v) Write a characterfinal voidwriteChars(String s) Write a String (Charset)final voidwriteDouble(double v) Write a doublefinal voidwriteFloat(float v) Write a floatfinal voidwriteInt(int v) Write an integerfinal voidwriteLong(long v) Write a longfinal voidwriteShort(int v) Write a shortfinal voidWrite a String (UTF)
-
Field Details
-
buf
protected byte[] buf
-
-
Constructor Details
-
DataBuffer
public DataBuffer()Create a buffer with 32 byte length of initial size -
DataBuffer
public DataBuffer(byte[] buff) Create a buffer with existing byte array- Parameters:
buff-
-
DataBuffer
Read the input stream and copy it to the buffer- Parameters:
input-- Throws:
IOException
-
DataBuffer
public DataBuffer(int initialSize) Create a buffer with specific initial size- Parameters:
initialSize-
-
-
Method Details
-
copyTo
Copy the buffer to the OutputStream- Parameters:
output-- Throws:
IOException
-
available
public int available()Get readable bytes (basically the current buffer size)- Returns:
-
clear
public void clear()Clear the buffer -
finalize
public void finalize()Flush the byte array -
read
public int read()Read a byte- Returns:
-
read
public int read(byte[] b, int off, int len) Read bytes at specific offset and length- Parameters:
b-off-len-- Returns:
-
read
public int read(byte[] bytes) Read and fill the provided byte array- Parameters:
bytes-- Returns:
-
readBoolean
public final boolean readBoolean()Read a boolean- Specified by:
readBooleanin interfaceDataInput
-
readByte
public final byte readByte()Read a byte -
readBytes
Read a string (non charset)- Returns:
-
readChar
public final char readChar()Read a character -
readChars
Read a string (using charset)- Returns:
-
readDouble
public final double readDouble()Read a double- Specified by:
readDoublein interfaceDataInput
-
readFloat
public final float readFloat()Read a float -
readFully
public final void readFully(byte[] b) Read and fill the provided byte array -
readFully
public final void readFully(byte[] b, int off, int len) Read and fill the provided byte array at specific offset and length -
readInt
public final int readInt()Read an integer -
readLine
Deprecated.Not supported -
readLong
public final long readLong()Read a long -
readShort
public final short readShort()Read a short -
readUnsignedByte
public final int readUnsignedByte()Read an unsigned byte- Specified by:
readUnsignedBytein interfaceDataInput
-
readUnsignedShort
public final int readUnsignedShort()Read an unsigned short- Specified by:
readUnsignedShortin interfaceDataInput
-
readUTF
Read a String (UTF) -
skip
public long skip(long n) Skip bytes- Parameters:
n-- Returns:
-
skipBytes
public final int skipBytes(int n) Skip bytes -
toByteArray
public byte[] toByteArray()Transform this buffer into a byte array- Returns:
-
write
public void write(byte[] b, int off, int len) Write byte array at specific offset and length to this buffer- Specified by:
writein interfaceDataOutput
-
write
public void write(byte[] b) Write byte array to this buffer- Specified by:
writein interfaceDataOutput
-
write
public void write(int b) Write a byte to this buffer- Specified by:
writein interfaceDataOutput
-
writeBoolean
public final void writeBoolean(boolean v) Write a boolean to this buffer- Specified by:
writeBooleanin interfaceDataOutput
-
writeByte
public final void writeByte(int v) Write a byte to this buffer- Specified by:
writeBytein interfaceDataOutput
-
writeBytes
Write a String (non Charset)- Specified by:
writeBytesin interfaceDataOutput
-
writeChar
public final void writeChar(int v) Write a character- Specified by:
writeCharin interfaceDataOutput
-
writeChars
Write a String (Charset)- Specified by:
writeCharsin interfaceDataOutput
-
writeDouble
public final void writeDouble(double v) Write a double- Specified by:
writeDoublein interfaceDataOutput
-
writeFloat
public final void writeFloat(float v) Write a float- Specified by:
writeFloatin interfaceDataOutput
-
writeInt
public final void writeInt(int v) Write an integer- Specified by:
writeIntin interfaceDataOutput
-
writeLong
public final void writeLong(long v) Write a long- Specified by:
writeLongin interfaceDataOutput
-
writeShort
public final void writeShort(int v) Write a short- Specified by:
writeShortin interfaceDataOutput
-
writeUTF
Write a String (UTF)- Specified by:
writeUTFin interfaceDataOutput
-