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
-
Constructor Summary
ConstructorDescriptionCreate 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 TypeMethodDescriptionint
Get readable bytes (basically the current buffer size)void
clear()
Clear the buffervoid
copyTo
(OutputStream output) Copy the buffer to the OutputStreamvoid
finalize()
Flush the byte arrayint
read()
Read a byteint
read
(byte[] bytes) Read and fill the provided byte arrayint
read
(byte[] b, int off, int len) Read bytes at specific offset and lengthfinal boolean
Read a booleanfinal byte
readByte()
Read a byteRead a string (non charset)final char
readChar()
Read a characterRead a string (using charset)final double
Read a doublefinal float
Read a floatfinal void
readFully
(byte[] b) Read and fill the provided byte arrayfinal void
readFully
(byte[] b, int off, int len) Read and fill the provided byte array at specific offset and lengthfinal int
readInt()
Read an integerfinal String
readLine()
Deprecated.final long
readLong()
Read a longfinal short
Read a shortfinal int
Read an unsigned bytefinal int
Read an unsigned shortfinal String
readUTF()
Read a String (UTF)long
skip
(long n) Skip bytesfinal int
skipBytes
(int n) Skip bytesbyte[]
Transform this buffer into a byte arrayvoid
write
(byte[] b) Write byte array to this buffervoid
write
(byte[] b, int off, int len) Write byte array at specific offset and length to this buffervoid
write
(int b) Write a byte to this bufferfinal void
writeBoolean
(boolean v) Write a boolean to this bufferfinal void
writeByte
(int v) Write a byte to this bufferfinal void
writeBytes
(String s) Write a String (non Charset)final void
writeChar
(int v) Write a characterfinal void
writeChars
(String s) Write a String (Charset)final void
writeDouble
(double v) Write a doublefinal void
writeFloat
(float v) Write a floatfinal void
writeInt
(int v) Write an integerfinal void
writeLong
(long v) Write a longfinal void
writeShort
(int v) Write a shortfinal void
Write 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:
readBoolean
in 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:
readDouble
in 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:
readUnsignedByte
in interfaceDataInput
-
readUnsignedShort
public final int readUnsignedShort()Read an unsigned short- Specified by:
readUnsignedShort
in 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:
write
in interfaceDataOutput
-
write
public void write(byte[] b) Write byte array to this buffer- Specified by:
write
in interfaceDataOutput
-
write
public void write(int b) Write a byte to this buffer- Specified by:
write
in interfaceDataOutput
-
writeBoolean
public final void writeBoolean(boolean v) Write a boolean to this buffer- Specified by:
writeBoolean
in interfaceDataOutput
-
writeByte
public final void writeByte(int v) Write a byte to this buffer- Specified by:
writeByte
in interfaceDataOutput
-
writeBytes
Write a String (non Charset)- Specified by:
writeBytes
in interfaceDataOutput
-
writeChar
public final void writeChar(int v) Write a character- Specified by:
writeChar
in interfaceDataOutput
-
writeChars
Write a String (Charset)- Specified by:
writeChars
in interfaceDataOutput
-
writeDouble
public final void writeDouble(double v) Write a double- Specified by:
writeDouble
in interfaceDataOutput
-
writeFloat
public final void writeFloat(float v) Write a float- Specified by:
writeFloat
in interfaceDataOutput
-
writeInt
public final void writeInt(int v) Write an integer- Specified by:
writeInt
in interfaceDataOutput
-
writeLong
public final void writeLong(long v) Write a long- Specified by:
writeLong
in interfaceDataOutput
-
writeShort
public final void writeShort(int v) Write a short- Specified by:
writeShort
in interfaceDataOutput
-
writeUTF
Write a String (UTF)- Specified by:
writeUTF
in interfaceDataOutput
-