Package com.iizix.nio

Class DataPacket

java.lang.Object
com.iizix.nio.DataPacket

public class DataPacket extends Object
This class implements the cryptographic interface for the client/server communication. The encryption algorithm is NOT intended for advanced encryption, rather to hide otherwise "visible" data such as user ID's and passwords.
  • Constructor Summary

    Constructors
    Constructor
    Description
    The default cryptographic interface only implements the most simple way of garbling the byte data.
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    compress(byte[] data, int length)
    Tries to compress the input data to a smaller chunk.
    static byte[]
    compress2(byte[] data, int length)
    Always compresses the input data to perhaps a smaller chunk.
    static byte[]
    decompress(byte[] data)
    Decompress the data.
    byte[]
    decrypt(byte[] indata, int offset, int len)
    Decrypts the data.
    byte[]
    encrypt(byte[] data, int length)
    Encrypts the data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DataPacket

      public DataPacket()
      The default cryptographic interface only implements the most simple way of garbling the byte data.

      In this implementation, nothing needs to be done in the constructor.

  • Method Details

    • encrypt

      public byte[] encrypt(byte[] data, int length)
      Encrypts the data. The decrypt method has to make sure that the same data that is input to the encrypt method is provided as a return to this method.

      Note: if any changes to the buffer is required and the buffer is of the same length, use the original buffer in order to spare the virtual machine of any memory freeing. In this case, the same buffer is returned as only the content have changed, not the size.

    • decrypt

      public byte[] decrypt(byte[] indata, int offset, int len)
      Decrypts the data.
      Parameters:
      indata - Input data.
      offset - Offset in input data.
      len - Length of input data.
    • compress

      public static byte[] compress(byte[] data, int length)
      Tries to compress the input data to a smaller chunk. If this chunk is not at least 2% smaller, the best thing is to use the data uncompressed and in this case the function will return null. If the input data size is less than 860 bytes, null is returned, thus no compression performed.
      Parameters:
      data - the input data to compress.
      Returns:
      The compressed data, or null if there is no need for compression.
    • compress2

      public static byte[] compress2(byte[] data, int length)
      Always compresses the input data to perhaps a smaller chunk.
      Parameters:
      data - the input data to compress.
      Returns:
      The compressed data, or data if there is no need for compression.
    • decompress

      public static byte[] decompress(byte[] data) throws IOException
      Decompress the data.
      Returns:
      The uncompressed data.
      Throws:
      IOException - for uncompress errors.