Class ReadTransaction
- All Implemented Interfaces:
- ITransaction
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 SummaryModifier and TypeMethodDescription- static ReadTransactionCreates 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.- intGets the remaining size in bytes for read methods in the transaction.- intGets the size of the read transaction.- booleanReads 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.- doubleReads a 64 bit double value from the incoming data.- floatReads a float value from the incoming data.- int- readLong()Reads a 32 bit signed value from the incoming data.- longReads a 64 bit signed value from the incoming data.- doubleReads a JavaScript Number from transaction.- intReads a 16 bit signed value from the incoming data.- intReads a signed integer of the range -0x1FFFFFFF to 0x1FFFFFFF.Reads a string from the incoming data.Retrieves a sub-transaction from an incoming transaction.- intReads an unsigned integer of the range 0x00000000 to 0x3FFFFFFF.- intReads a 16 bit unsigned value from the incoming data.- void- skipBytes- (int count) Skips a number of bytes for reading.
- Method Details- getLongDatapublic 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.
 
- fromCreates 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.
 
- getBytepublic 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.
 
- readTransactionRetrieves 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.
 
- getRemainingReadSizepublic 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.
 
- getTotalReadSizepublic int getTotalReadSize()Gets the size of the read transaction.- Returns:
- Byte count value.
 
- skipBytespublic 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.
 
- readBytepublic 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.
 
- readBytespublic 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.
 
- readCharpublic 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.
 
- readBooleanpublic 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.
 
- readUnsignedpublic 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.
 
- readSignedpublic 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.
 
- readShortpublic 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.
 
- readUShortpublic 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.
 
- readLongpublic int readLong()Reads a 32 bit signed value from the incoming data.- Returns:
- A value Integer.MIN_VALUEtoInteger.MAX_VALUE.
- Throws:
- IllegalStateException- For wrong data type.
- RuntimeException- If the position exceeds the read buffer.
 
- readLong64public long readLong64()Reads a 64 bit signed value from the incoming data.- Returns:
- A value Long.MIN_VALUEtoLong.MAX_VALUE.
- Throws:
- IllegalStateException- For wrong data type.
- RuntimeException- If the position exceeds the read buffer.
 
- readFloatpublic 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.
 
- readDoublepublic 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.
 
- readNumberpublic 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.
 
- readStringReads 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.