Class ReadTransaction
- java.lang.Object
- com.iizix.ReadTransaction
- All Implemented Interfaces:
ITransaction
public class ReadTransaction extends java.lang.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
Field Summary
Fields inherited from interface com.iizix.ITransaction
DESCR_BOOLEAN, DESCR_BYTE, DESCR_BYTES, DESCR_CHAR, DESCR_DOUBLE, DESCR_FLOAT, DESCR_LONG, DESCR_LONG64, DESCR_NUMBER, DESCR_SHORT, DESCR_SIGNED_INT, DESCR_STRING, DESCR_TRANSACTION, DESCR_UNSIGNED_INT, DESCR_USHORT, TYPE_BOOLEAN, TYPE_BYTE, TYPE_BYTES, TYPE_CHAR, TYPE_DOUBLE, TYPE_FLOAT, TYPE_LONG, TYPE_LONG64, TYPE_NUMBER, TYPE_SHORT, TYPE_SIGNED_INT, TYPE_STRING, TYPE_TRANSACTION, TYPE_UNSIGNED_INT, TYPE_USHORT
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ReadTransaction
from(byte[] data, java.util.HashMap<java.lang.Integer,java.lang.String> readCache)
Creates a transaction with a read cache.int
getByte()
Get an unsigned byte from the incoming data without moving the read position.static byte[]
getLongData(int val)
Static helper method to get the 4-byte representation of a 32 bit signed value.int
getRemainingReadSize()
Gets the remaining size in bytes for read methods in the transaction.int
getTotalReadSize()
Gets the size of the read transaction.boolean
readBoolean()
Reads a boolean from incoming data.int
readByte()
Reads an unsigned byte from the incoming data.byte[]
readBytes(int count)
Reads a byte array from the incoming data.char
readChar()
Reads an encoded character in a byte from the incoming data.double
readDouble()
Reads a 64 bit double value from the incoming data.float
readFloat()
Reads a float value from the incoming data.int
readLong()
Reads a 32 bit signed value from the incoming data.long
readLong64()
Reads a 64 bit signed value from the incoming data.double
readNumber()
Reads a JavaScript Number from transaction.int
readShort()
Reads a 16 bit signed value from the incoming data.int
readSigned()
Reads a signed integer of the range -0x1FFFFFFF to 0x1FFFFFFF.java.lang.String
readString()
Reads a string from the incoming data.ReadTransaction
readTransaction()
Retrieves a sub-transaction from an incoming transaction.int
readUnsigned()
Reads an unsigned integer of the range 0x00000000 to 0x3FFFFFFF.int
readUShort()
Reads a 16 bit unsigned value from the incoming data.void
skipBytes(int count)
Skips a number of bytes for reading.
Method Detail
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, java.util.HashMap<java.lang.Integer,java.lang.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:
java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.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:
java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.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
toInteger.MAX_VALUE
. - Throws:
java.lang.IllegalStateException
- For wrong data type.java.lang.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
toLong.MAX_VALUE
. - Throws:
java.lang.IllegalStateException
- For wrong data type.java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.RuntimeException
- If the position exceeds the read buffer.
readString
public java.lang.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:
java.lang.IllegalStateException
- For wrong data type.java.lang.RuntimeException
- If the position exceeds the read buffer, or the String does not exist in read cache.