Class DataBuffer

java.lang.Object
septogeddon.pluginquery.utils.DataBuffer
All Implemented Interfaces:
DataInput, DataOutput
Direct Known Subclasses:
ObjectBuffer

public class DataBuffer extends Object implements DataInput, DataOutput
DataBuffer for PluginQuery. Hold objects in byte buffer to send later or read later.
Author:
Thito Yalasatria Sunarya
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected byte[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a buffer with 32 byte length of initial size
    DataBuffer(byte[] buff)
    Create a buffer with existing byte array
    DataBuffer(int initialSize)
    Create a buffer with specific initial size
    Read the input stream and copy it to the buffer
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Get readable bytes (basically the current buffer size)
    void
    Clear the buffer
    void
    Copy the buffer to the OutputStream
    void
    Flush the byte array
    int
    Read a byte
    int
    read(byte[] bytes)
    Read and fill the provided byte array
    int
    read(byte[] b, int off, int len)
    Read bytes at specific offset and length
    final boolean
    Read a boolean
    final byte
    Read a byte
    Read a string (non charset)
    final char
    Read a character
    Read a string (using charset)
    final double
    Read a double
    final float
    Read a float
    final void
    readFully(byte[] b)
    Read and fill the provided byte array
    final void
    readFully(byte[] b, int off, int len)
    Read and fill the provided byte array at specific offset and length
    final int
    Read an integer
    final String
    Deprecated.
    final long
    Read a long
    final short
    Read a short
    final int
    Read an unsigned byte
    final int
    Read an unsigned short
    final String
    Read a String (UTF)
    long
    skip(long n)
    Skip bytes
    final int
    skipBytes(int n)
    Skip bytes
    byte[]
    Transform this buffer into a byte array
    void
    write(byte[] b)
    Write byte array to this buffer
    void
    write(byte[] b, int off, int len)
    Write byte array at specific offset and length to this buffer
    void
    write(int b)
    Write a byte to this buffer
    final void
    writeBoolean(boolean v)
    Write a boolean to this buffer
    final void
    writeByte(int v)
    Write a byte to this buffer
    final void
    Write a String (non Charset)
    final void
    writeChar(int v)
    Write a character
    final void
    Write a String (Charset)
    final void
    writeDouble(double v)
    Write a double
    final void
    writeFloat(float v)
    Write a float
    final void
    writeInt(int v)
    Write an integer
    final void
    writeLong(long v)
    Write a long
    final void
    writeShort(int v)
    Write a short
    final void
    Write a String (UTF)

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public DataBuffer(InputStream input) throws IOException
      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

      public void copyTo(OutputStream output) throws IOException
      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
      Overrides:
      finalize in class Object
    • 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 interface DataInput
    • readByte

      public final byte readByte()
      Read a byte
      Specified by:
      readByte in interface DataInput
    • readBytes

      public String readBytes()
      Read a string (non charset)
      Returns:
    • readChar

      public final char readChar()
      Read a character
      Specified by:
      readChar in interface DataInput
    • readChars

      public String readChars()
      Read a string (using charset)
      Returns:
    • readDouble

      public final double readDouble()
      Read a double
      Specified by:
      readDouble in interface DataInput
    • readFloat

      public final float readFloat()
      Read a float
      Specified by:
      readFloat in interface DataInput
    • readFully

      public final void readFully(byte[] b)
      Read and fill the provided byte array
      Specified by:
      readFully in interface DataInput
    • readFully

      public final void readFully(byte[] b, int off, int len)
      Read and fill the provided byte array at specific offset and length
      Specified by:
      readFully in interface DataInput
    • readInt

      public final int readInt()
      Read an integer
      Specified by:
      readInt in interface DataInput
    • readLine

      @Deprecated public final String readLine()
      Deprecated.
      Not supported
      Specified by:
      readLine in interface DataInput
    • readLong

      public final long readLong()
      Read a long
      Specified by:
      readLong in interface DataInput
    • readShort

      public final short readShort()
      Read a short
      Specified by:
      readShort in interface DataInput
    • readUnsignedByte

      public final int readUnsignedByte()
      Read an unsigned byte
      Specified by:
      readUnsignedByte in interface DataInput
    • readUnsignedShort

      public final int readUnsignedShort()
      Read an unsigned short
      Specified by:
      readUnsignedShort in interface DataInput
    • readUTF

      public final String readUTF()
      Read a String (UTF)
      Specified by:
      readUTF in interface DataInput
    • skip

      public long skip(long n)
      Skip bytes
      Parameters:
      n -
      Returns:
    • skipBytes

      public final int skipBytes(int n)
      Skip bytes
      Specified by:
      skipBytes in interface DataInput
    • 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 interface DataOutput
    • write

      public void write(byte[] b)
      Write byte array to this buffer
      Specified by:
      write in interface DataOutput
    • write

      public void write(int b)
      Write a byte to this buffer
      Specified by:
      write in interface DataOutput
    • writeBoolean

      public final void writeBoolean(boolean v)
      Write a boolean to this buffer
      Specified by:
      writeBoolean in interface DataOutput
    • writeByte

      public final void writeByte(int v)
      Write a byte to this buffer
      Specified by:
      writeByte in interface DataOutput
    • writeBytes

      public final void writeBytes(String s)
      Write a String (non Charset)
      Specified by:
      writeBytes in interface DataOutput
    • writeChar

      public final void writeChar(int v)
      Write a character
      Specified by:
      writeChar in interface DataOutput
    • writeChars

      public final void writeChars(String s)
      Write a String (Charset)
      Specified by:
      writeChars in interface DataOutput
    • writeDouble

      public final void writeDouble(double v)
      Write a double
      Specified by:
      writeDouble in interface DataOutput
    • writeFloat

      public final void writeFloat(float v)
      Write a float
      Specified by:
      writeFloat in interface DataOutput
    • writeInt

      public final void writeInt(int v)
      Write an integer
      Specified by:
      writeInt in interface DataOutput
    • writeLong

      public final void writeLong(long v)
      Write a long
      Specified by:
      writeLong in interface DataOutput
    • writeShort

      public final void writeShort(int v)
      Write a short
      Specified by:
      writeShort in interface DataOutput
    • writeUTF

      public final void writeUTF(String str)
      Write a String (UTF)
      Specified by:
      writeUTF in interface DataOutput