Class WritablePacket<T extends Client<Connection<T>>>


  • public abstract class WritablePacket<T extends Client<Connection<T>>>
    extends java.lang.Object
    This class represents a Packet that can be sent to clients. All data sent 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 WritablePacket()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String toString()  
      protected abstract boolean write​(T client)
      Writes the data to the client
      protected void writeByte​(boolean value)
      Write boolean to the buffer.
      protected void writeByte​(byte value)
      Write abyte to the buffer.
      protected void writeByte​(int value)
      Write a int to the buffer, the int is casted to a byte;
      protected void writeBytes​(byte... bytes)
      Write byte[] to the buffer.
      protected void writeChar​(char value)
      Write char to the buffer.
      16 bit char
      protected void writeDouble​(double value)
      Write double to the buffer.
      protected void writeFloat​(float value)
      Write float to the buffer.
      protected void writeInt​(boolean value)
      Write boolean to the buffer.
      protected void writeInt​(int value)
      Write int to the buffer.
      protected void writeLong​(long value)
      Write long to the buffer.
      protected void writeShort​(boolean value)
      Write boolean to the buffer.
      protected void writeShort​(int value)
      Write short to the buffer.
      protected void writeSizedString​(java.lang.CharSequence text)
      Write String to the buffer preceded by a short 16 bit with String length and no null termination.
      protected void writeString​(java.lang.CharSequence text)
      Write a String to the buffer with a null termination (\000).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • WritablePacket

        protected WritablePacket()
    • Method Detail

      • writeBytes

        protected final void writeBytes​(byte... bytes)
        Write byte[] to the buffer.
        8bit integer array (00 ...)
        Parameters:
        bytes - to be written
      • writeByte

        protected final void writeByte​(byte value)
        Write abyte to the buffer.
        8bit integer (00) If the underlying data array can't hold a new byte its size is increased 20%
        Parameters:
        value - to be written
      • writeByte

        protected final void writeByte​(int value)
        Write a int to the buffer, the int is casted to a byte;
        Parameters:
        value - to be written
      • writeByte

        protected final void writeByte​(boolean value)
        Write boolean to the buffer.
        If the value is true so write a byte with value 1, otherwise 0 8bit integer (00)
        Parameters:
        value - to be written
      • writeDouble

        protected final void writeDouble​(double value)
        Write double to the buffer.
        64bit double precision float (00 00 00 00 00 00 00 00)
        Parameters:
        value - to be written
      • writeShort

        protected final void writeShort​(int value)
        Write short to the buffer.
        16bit integer (00 00)
        Parameters:
        value - to be written
      • writeShort

        protected final void writeShort​(boolean value)
        Write boolean to the buffer.
        If the value is true so write a byte with value 1, otherwise 0 16bit integer (00 00)
        Parameters:
        value - to be written
      • writeInt

        protected final void writeInt​(int value)
        Write int to the buffer.
        32bit integer (00 00 00 00)
        Parameters:
        value - to be written
      • writeInt

        protected final void writeInt​(boolean value)
        Write boolean to the buffer.
        If the value is true so write a byte with value 1, otherwise 0 32bit integer (00 00 00 00)
        Parameters:
        value - to be written
      • writeFloat

        protected final void writeFloat​(float value)
        Write float to the buffer.
        32bit float point number (00 00 00 00)
        Parameters:
        value - to be written
      • writeLong

        protected final void writeLong​(long value)
        Write long to the buffer.
        64bit integer (00 00 00 00 00 00 00 00)
        Parameters:
        value - to be written
      • writeChar

        protected final void writeChar​(char value)
        Write char to the buffer.
        16 bit char
        Parameters:
        value - the char to be put on data.
      • writeString

        protected final void writeString​(java.lang.CharSequence text)
        Write a String to the buffer with a null termination (\000). Each character is a 16bit char
        Parameters:
        text - to be written
      • writeSizedString

        protected final void writeSizedString​(java.lang.CharSequence text)
        Write String to the buffer preceded by a short 16 bit with String length and no null termination. Each character is a 16bit char.
        Parameters:
        text - to be written
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • write

        protected abstract boolean write​(T client)
        Writes the data to the client
        Parameters:
        client - client to send data
        Returns:
        the packet was written successful