Package org.firebirdsql.gds
Class VaxEncoding
- java.lang.Object
-
- org.firebirdsql.gds.VaxEncoding
-
public final class VaxEncoding extends java.lang.Object
Helper methods for decoding Vax style (little endian) integers as used by Firebird from byte arrays.- Since:
- 3.0
- Author:
- Mark Rotteveel
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
encodeVaxInteger(java.io.OutputStream stream, int value)
Encodes an integer using vax encoding into the output stream, length prefix is included.static void
encodeVaxInteger2WithoutLength(java.io.OutputStream stream, int value)
Encodes an integer using two byte vax encoding into the output stream, without length prefix.static void
encodeVaxIntegerWithoutLength(java.io.OutputStream stream, int value)
Encodes an integer using vax encoding into the output stream, without length prefix.static void
encodeVaxLong(java.io.OutputStream stream, long value)
Encodes a long using vax encoding into the output stream, length prefix is included.static void
encodeVaxLongWithoutLength(java.io.OutputStream stream, long value)
Encodes a long using vax encoding into the output stream, without length prefix.static int
iscVaxInteger(byte[] buffer, int startPosition, int length)
Reads Vax style integers from the supplied buffer, starting atstartPosition
and reading forlength
bytes.static int
iscVaxInteger2(byte[] buffer, int startPosition)
Variant ofiscVaxInteger(byte[], int, int)
specifically for two-byte integers.static long
iscVaxLong(byte[] buffer, int startPosition, int length)
Reads Vax style integers from the supplied buffer, starting atstartPosition
and reading forlength
bytes.
-
-
-
Method Detail
-
iscVaxInteger
public static int iscVaxInteger(byte[] buffer, int startPosition, int length)
Reads Vax style integers from the supplied buffer, starting atstartPosition
and reading forlength
bytes.This method is useful for lengths up to 4 bytes (ie normal Java integers (
int
). For larger lengths it will return0
. UseiscVaxLong(byte[], int, int)
for reading values with length up to 8 bytes. For decoding 2 byte integers, useiscVaxInteger2(byte[], int)
for optimal performance.- Parameters:
buffer
- The byte array from which the integer is to be retrievedstartPosition
- The offset starting position from which to start retrieving byte valueslength
- number of bytes to read- Returns:
- The integer value retrieved from the bytes
- See Also:
iscVaxLong(byte[], int, int)
,iscVaxInteger2(byte[], int)
-
encodeVaxInteger
public static void encodeVaxInteger(java.io.OutputStream stream, int value) throws java.io.IOException
Encodes an integer using vax encoding into the output stream, length prefix is included.- Parameters:
stream
- Output stream to writevalue
- Value to encode- Throws:
java.io.IOException
-
encodeVaxIntegerWithoutLength
public static void encodeVaxIntegerWithoutLength(java.io.OutputStream stream, int value) throws java.io.IOException
Encodes an integer using vax encoding into the output stream, without length prefix.- Parameters:
stream
- Output stream to writevalue
- Value to encode- Throws:
java.io.IOException
-
iscVaxLong
public static long iscVaxLong(byte[] buffer, int startPosition, int length)
Reads Vax style integers from the supplied buffer, starting atstartPosition
and reading forlength
bytes.This method is useful for lengths up to 8 bytes (ie normal Java longs (
long
). For larger lengths it will return0
.- Parameters:
buffer
- The byte array from which the integer is to be retrievedstartPosition
- The offset starting position from which to start retrieving byte valueslength
- number of bytes to read- Returns:
- The integer value retrieved from the bytes
- See Also:
iscVaxInteger(byte[], int, int)
,iscVaxInteger2(byte[], int)
-
encodeVaxLong
public static void encodeVaxLong(java.io.OutputStream stream, long value) throws java.io.IOException
Encodes a long using vax encoding into the output stream, length prefix is included.- Parameters:
stream
- Output stream to writevalue
- Value to encode- Throws:
java.io.IOException
-
encodeVaxLongWithoutLength
public static void encodeVaxLongWithoutLength(java.io.OutputStream stream, long value) throws java.io.IOException
Encodes a long using vax encoding into the output stream, without length prefix.- Parameters:
stream
- Output stream to writevalue
- Value to encode- Throws:
java.io.IOException
-
iscVaxInteger2
public static int iscVaxInteger2(byte[] buffer, int startPosition)
Variant ofiscVaxInteger(byte[], int, int)
specifically for two-byte integers.- Parameters:
buffer
- The byte array from which the integer is to be retrievedstartPosition
- The offset starting position from which to start retrieving byte values- Returns:
- The integer value retrieved from the bytes
- See Also:
iscVaxInteger(byte[], int, int)
,iscVaxLong(byte[], int, int)
-
encodeVaxInteger2WithoutLength
public static void encodeVaxInteger2WithoutLength(java.io.OutputStream stream, int value) throws java.io.IOException
Encodes an integer using two byte vax encoding into the output stream, without length prefix.- Parameters:
stream
- Output stream to writevalue
- Value to encode- Throws:
java.io.IOException
-
-