Class ReadablePacket<T>

  • All Implemented Interfaces:
    java.lang.Runnable
    Direct Known Subclasses:
    DataWrapper

    public abstract class ReadablePacket<T>
    extends AbstractPacket<T>
    implements java.lang.Runnable
    This class represents a Packet received from the client. All data received must have a header with 2 bytes and an optional payload. The first and second bytes is a 16 bits integer holding the size of the packet.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ReadablePacket()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected int availableData()  
      protected abstract boolean read()  
      protected byte readByte()
      Reads raw byte from the buffer
      protected void readBytes​(byte[] dst)
      Reads as many bytes as the length of the array.
      protected void readBytes​(byte[] dst, int offset, int length)
      Reads as many bytes as the given length (len).
      protected char readChar()
      Reads char from the buffer
      protected double readDouble()
      Reads double from the buffer.
      protected float readFloat()
      Reads float from the buffer.
      protected int readInt()
      Reads int from the buffer.
      protected long readLong()
      Reads long from the buffer.
      protected short readShort()
      Reads short from the buffer.
      protected java.lang.String readSizedString()
      Reads a predefined length String from the buffer.
      protected java.lang.String readString()
      Reads String from the buffer.
      protected int readUnsignedByte()
      Reads byte from the buffer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Runnable

        run
    • Constructor Detail

      • ReadablePacket

        protected ReadablePacket()
    • Method Detail

      • availableData

        protected final int availableData()
      • readBytes

        protected final void readBytes​(byte[] dst)
        Reads as many bytes as the length of the array.
        Parameters:
        dst - : the byte array which will be filled with the data.
      • readBytes

        protected final void readBytes​(byte[] dst,
                                       int offset,
                                       int length)
        Reads as many bytes as the given length (len). Starts to fill the byte array from the given offset to offset + len.
        Parameters:
        dst - : the byte array which will be filled with the data.
        offset - : starts to fill the byte array from the given offset.
        length - : the given length of bytes to be read.
      • readByte

        protected final byte readByte()
        Reads raw byte from the buffer
        Returns:
        byte read
      • readChar

        protected final char readChar()
        Reads char from the buffer
        Returns:
        char read
      • readUnsignedByte

        protected final int readUnsignedByte()
        Reads byte from the buffer.
        8bit integer (00)
        Returns:
        unsigned int read
      • readShort

        protected final short readShort()
        Reads short from the buffer.
        16bit integer (00 00)
        Returns:
        short read
      • readFloat

        protected final float readFloat()
        Reads float from the buffer.
        32bit precision float (00 00 00 00)
        Returns:
        float read
      • readInt

        protected final int readInt()
        Reads int from the buffer.
        32bit integer (00 00 00 00)
        Returns:
        int read
      • readLong

        protected final long readLong()
        Reads long from the buffer.
        64bit integer (00 00 00 00 00 00 00 00)
        Returns:
        long read
      • readDouble

        protected final double readDouble()
        Reads double from the buffer.
        64bit double precision float (00 00 00 00 00 00 00 00)
        Returns:
        double read
      • readString

        protected final java.lang.String readString()
        Reads String from the buffer.
        Returns:
        String read
      • readSizedString

        protected final java.lang.String readSizedString()
        Reads a predefined length String from the buffer.
        Returns:
        String read
      • read

        protected abstract boolean read()