Package com.iizix

Class ReadTransaction

java.lang.Object
com.iizix.ReadTransaction
All Implemented Interfaces:
ITransaction

public class ReadTransaction extends Object implements ITransaction
This transaction class is used for all communication between the Server, Client and Remote Administration programs. It is used to stream out transaction specific data that is streamed in on the other end.

Note: All "synchronization" calls are now removed for performance reasons, so threaded access to a transaction instance should be synchronized by the calling threads.

Author:
Christopher Mindus
  • Method Details

    • getLongData

      public static byte[] getLongData(int val)
      Static helper method to get the 4-byte representation of a 32 bit signed value.
      Parameters:
      val - The 32-bit value.
      Returns:
      A byte array of 4 in length of the 32-bit value.
    • from

      public static ReadTransaction from(byte[] data, HashMap<Integer,String> readCache)
      Creates a transaction with a read cache.
      Parameters:
      data - The data array to initialize this read-type transaction with.
      readCache - The read cache to use, null for none.
    • getByte

      public int getByte()
      Get an unsigned byte from the incoming data without moving the read position.
      Returns:
      A byte value 0x00 to 0xFF.
      Throws:
      RuntimeException - If the position exceeds the read buffer.
    • readTransaction

      public ReadTransaction readTransaction()
      Retrieves a sub-transaction from an incoming transaction.
      Returns:
      null if no more sub-transactions exist.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • getRemainingReadSize

      public int getRemainingReadSize()
      Gets the remaining size in bytes for read methods in the transaction. This is useful to see if a transaction has read all its data.
      Returns:
      Byte count value.
    • getTotalReadSize

      public int getTotalReadSize()
      Gets the size of the read transaction.
      Returns:
      Byte count value.
    • skipBytes

      public void skipBytes(int count)
      Skips a number of bytes for reading.
      Parameters:
      count - Count of bytes to skip in the read data.
      Throws:
      IllegalArgumentException - If count is negative or if count is too large and is past the buffer.
    • readByte

      public int readByte()
      Reads an unsigned byte from the incoming data.
      Returns:
      A byte value 0-255 from the data.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readBytes

      public byte[] readBytes(int count)
      Reads a byte array from the incoming data.
      Parameters:
      count - Count of bytes to read.
      Returns:
      The newly allocated bytes read.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readChar

      public char readChar()
      Reads an encoded character in a byte from the incoming data. If the transactions use Unicode only, two bytes are read, otherwise just one using the codepage conversion or the default ISO 8859-1 character set. A unicode character is preceded with the '\xFF' character, meaning that 3 bytes are used for the Unicode character.

      The character has, due to Java itself, a code point between U+0000 and U+FFFF, i.e. 16 bits. The additional so called "surrogate pair characters" (two "char" in an array) having the code points U+000000 to U+10FFFF cannot be used here.

      The range of legal code points is now U+0000 to U+10FFFF, known as Unicode scalar value. The set of characters from U+0000 to U+FFFF is sometimes referred to as the Basic Multilingual Plane (BMP). Characters whose code points are greater than U+FFFF are called supplementary characters, and not supported here.

      Encoding: if the character ASCII (code point) value is up to 254 inclusive (i.e. smaller than 0xFF), a single byte is added, otherwise 3 character.

      Returns:
      the character read.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readBoolean

      public boolean readBoolean()
      Reads a boolean from incoming data.
      Returns:
      true if read byte is non-zero, false otherwise.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readUnsigned

      public int readUnsigned()
      Reads an unsigned integer of the range 0x00000000 to 0x3FFFFFFF. The space occupied in the transaction is 1 to 4 bytes.
      Returns:
      The unsigned integer.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readSigned

      public int readSigned()
      Reads a signed integer of the range -0x1FFFFFFF to 0x1FFFFFFF. The space occupied in the transaction is 1 to 4 bytes.
      Returns:
      The signed integer.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readShort

      public int readShort()
      Reads a 16 bit signed value from the incoming data.
      Returns:
      A value -0x8000 to 0x7FFF.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readUShort

      public int readUShort()
      Reads a 16 bit unsigned value from the incoming data.
      Returns:
      A value 0x0000 to 0xFFFF.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readLong

      public int readLong()
      Reads a 32 bit signed value from the incoming data.
      Returns:
      A value Integer.MIN_VALUE to Integer.MAX_VALUE.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readLong64

      public long readLong64()
      Reads a 64 bit signed value from the incoming data.
      Returns:
      A value Long.MIN_VALUE to Long.MAX_VALUE.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readFloat

      public float readFloat()
      Reads a float value from the incoming data.
      Returns:
      A float value (32 bits).
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readDouble

      public double readDouble()
      Reads a 64 bit double value from the incoming data.
      Returns:
      A double value (64 bits).
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readNumber

      public double readNumber()
      Reads a JavaScript Number from transaction.
      Returns:
      A double Number value (64 bits).
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer.
    • readString

      public String readString()
      Reads a string from the incoming data. The string may be encoded in Ansi or Unicode formats.
      Returns:
      the string read, possibly using a read cache.
      Throws:
      IllegalStateException - For wrong data type.
      RuntimeException - If the position exceeds the read buffer, or the String does not exist in read cache.