Class VaxEncoding

java.lang.Object
org.firebirdsql.gds.VaxEncoding

public final class VaxEncoding extends Object
Helper methods for decoding Vax style (little endian) integers as used by Firebird from byte arrays.
Since:
3.0
Author:
Mark Rotteveel
  • Method Details

    • iscVaxInteger

      public static int iscVaxInteger(byte[] buffer, int startPosition, int length)
      Reads Vax style integers from the supplied buffer, starting at startPosition and reading for length bytes.

      This method is useful for lengths up to 4 bytes (ie normal Java integers (int). For larger lengths it will return 0. Use iscVaxLong(byte[], int, int) for reading values with length up to 8 bytes. For decoding 2 byte integers, use iscVaxInteger2(byte[], int) for optimal performance.

      Parameters:
      buffer - The byte array from which the integer is to be retrieved
      startPosition - The offset starting position from which to start retrieving byte values
      length - number of bytes to read
      Returns:
      The integer value retrieved from the bytes
      See Also:
    • encodeVaxInteger

      public static void encodeVaxInteger(OutputStream stream, int value) throws IOException
      Encodes an integer using vax encoding into the output stream, length prefix is included.
      Parameters:
      stream - Output stream to write
      value - Value to encode
      Throws:
      IOException
    • encodeVaxIntegerWithoutLength

      public static void encodeVaxIntegerWithoutLength(OutputStream stream, int value) throws IOException
      Encodes an integer using vax encoding into the output stream, without length prefix.
      Parameters:
      stream - Output stream to write
      value - Value to encode
      Throws:
      IOException
    • iscVaxLong

      public static long iscVaxLong(byte[] buffer, int startPosition, int length)
      Reads Vax style integers from the supplied buffer, starting at startPosition and reading for length bytes.

      This method is useful for lengths up to 8 bytes (ie normal Java longs (long). For larger lengths it will return 0.

      Parameters:
      buffer - The byte array from which the integer is to be retrieved
      startPosition - The offset starting position from which to start retrieving byte values
      length - number of bytes to read
      Returns:
      The integer value retrieved from the bytes
      See Also:
    • encodeVaxLong

      public static void encodeVaxLong(OutputStream stream, long value) throws IOException
      Encodes a long using vax encoding into the output stream, length prefix is included.
      Parameters:
      stream - Output stream to write
      value - Value to encode
      Throws:
      IOException
    • encodeVaxLongWithoutLength

      public static void encodeVaxLongWithoutLength(OutputStream stream, long value) throws IOException
      Encodes a long using vax encoding into the output stream, without length prefix.
      Parameters:
      stream - Output stream to write
      value - Value to encode
      Throws:
      IOException
    • iscVaxInteger2

      public static int iscVaxInteger2(byte[] buffer, int startPosition)
      Variant of iscVaxInteger(byte[], int, int) specifically for two-byte integers.
      Parameters:
      buffer - The byte array from which the integer is to be retrieved
      startPosition - The offset starting position from which to start retrieving byte values
      Returns:
      The integer value retrieved from the bytes
      See Also:
    • encodeVaxInteger2WithoutLength

      public static void encodeVaxInteger2WithoutLength(OutputStream stream, int value) throws IOException
      Encodes an integer using two byte vax encoding into the output stream, without length prefix.
      Parameters:
      stream - Output stream to write
      value - Value to encode
      Throws:
      IOException