Module org.firebirdsql.jaybird
Package org.firebirdsql.gds

# Class VaxEncoding

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

@NullMarked 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 Summary

  Modifier and Type
  Method
  Description
  `static int`
  `decodeVaxInteger2WithoutLength(InputStream in)`
  Decodes an integer using two byte Vax encoding from an input stream, without length prefix.
  `static void`
  `encodeVaxInteger(byte[] buf, int off, int val)`
  Encodes an integer using Vax encoding into `buf`, length prefix is included.
  `static void`
  `encodeVaxInteger(OutputStream out, int val)`
  Encodes an integer using Vax encoding into an output stream, length prefix is included.
  `static void`
  `encodeVaxInteger2WithoutLength(byte[] buf, int off, int val)`
  Encodes an integer using two byte Vax encoding into `buf`, without length prefix.
  `static void`
  `encodeVaxInteger2WithoutLength(OutputStream out, int val)`
  Encodes an integer using two byte Vax encoding into an output stream, without length prefix.
  `static void`
  `encodeVaxIntegerWithoutLength(byte[] buf, int off, int val)`
  Encodes an integer using Vax encoding into `buf`, without length prefix.
  `static void`
  `encodeVaxIntegerWithoutLength(OutputStream out, int val)`
  Encodes an integer using Vax encoding into an output stream, without length prefix.
  `static void`
  `encodeVaxLong(byte[] buf, int off, long val)`
  Encodes a long using Vax encoding into `buf`, length prefix is included.
  `static void`
  `encodeVaxLong(OutputStream out, long val)`
  Encodes a long using Vax encoding into an output stream, length prefix is included.
  `static void`
  `encodeVaxLongWithoutLength(byte[] buf, int off, long val)`
  Encodes a long using Vax encoding into `buf`, without length prefix.
  `static void`
  `encodeVaxLongWithoutLength(OutputStream out, long val)`
  Encodes a long using Vax encoding into an output stream, without length prefix.
  `static int`
  `iscVaxInteger(byte[] buf, int off, int len)`
  Reads Vax style integers from `buf`, starting at `off` and reading for `len` bytes.
  `static int`
  `iscVaxInteger2(byte[] buf, int off)`
  Variant of `iscVaxInteger(byte[], int, int)` specifically for two-byte integers.
  `static long`
  `iscVaxLong(byte[] buf, int off, int len)`
  Reads Vax style integers (longs) from `buf`, starting at `off` and reading for `len` bytes.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### iscVaxInteger

    public static int iscVaxInteger(byte[] buf, int off, int len)
    Reads Vax style integers from `buf`, starting at `off` and reading for `len` bytes.

    This method is useful for lengths up to 4 bytes (i.e. 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:
      `buf` - byte array from which the integer is to be retrieved
      `off` - offset from which to start retrieving byte values
      `len` - number of bytes to read
    Returns:
      integer value retrieved from the bytes
    See Also:
      - `iscVaxLong(byte[], int, int)`
      - `iscVaxInteger2(byte[], int)`

  - ### encodeVaxInteger

    public static void encodeVaxInteger(OutputStream out, int val) throws IOException
    Encodes an integer using Vax encoding into an output stream, length prefix is included.
    Parameters:
      `out` - output stream to write
      `val` - value to encode
    Throws:
      `IOException`

  - ### encodeVaxInteger

    public static void encodeVaxInteger(byte[] buf, int off, int val)
    Encodes an integer using Vax encoding into `buf`, length prefix is included.
    Parameters:
      `buf` - byte array of sufficient size
      `off` - offset to start writing
      `val` - value to encode

  - ### encodeVaxIntegerWithoutLength

    public static void encodeVaxIntegerWithoutLength(OutputStream out, int val) throws IOException
    Encodes an integer using Vax encoding into an output stream, without length prefix.
    Parameters:
      `out` - output stream to write
      `val` - value to encode
    Throws:
      `IOException`

  - ### encodeVaxIntegerWithoutLength

    public static void encodeVaxIntegerWithoutLength(byte[] buf, int off, int val)
    Encodes an integer using Vax encoding into `buf`, without length prefix.
    Parameters:
      `buf` - byte array of sufficient size
      `off` - offset to start writing
      `val` - value to encode

  - ### iscVaxLong

    public static long iscVaxLong(byte[] buf, int off, int len)
    Reads Vax style integers (longs) from `buf`, starting at `off` and reading for `len` bytes.

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

    Parameters:
      `buf` - byte array from which the long is to be retrieved
      `off` - offset from which to start retrieving byte values
      `len` - number of bytes to read
    Returns:
      long value retrieved from the bytes
    See Also:
      - `iscVaxInteger(byte[], int, int)`
      - `iscVaxInteger2(byte[], int)`

  - ### encodeVaxLong

    public static void encodeVaxLong(OutputStream out, long val) throws IOException
    Encodes a long using Vax encoding into an output stream, length prefix is included.
    Parameters:
      `out` - output stream to write
      `val` - value to encode
    Throws:
      `IOException`

  - ### encodeVaxLong

    public static void encodeVaxLong(byte[] buf, int off, long val)
    Encodes a long using Vax encoding into `buf`, length prefix is included.
    Parameters:
      `buf` - byte array of sufficient size
      `off` - offset to start writing
      `val` - value to encode

  - ### encodeVaxLongWithoutLength

    public static void encodeVaxLongWithoutLength(OutputStream out, long val) throws IOException
    Encodes a long using Vax encoding into an output stream, without length prefix.
    Parameters:
      `out` - output stream to write
      `val` - value to encode
    Throws:
      `IOException`

  - ### encodeVaxLongWithoutLength

    public static void encodeVaxLongWithoutLength(byte[] buf, int off, long val)
    Encodes a long using Vax encoding into `buf`, without length prefix.
    Parameters:
      `buf` - byte array of sufficient size
      `off` - offset to start writing
      `val` - value to encode

  - ### iscVaxInteger2

    public static int iscVaxInteger2(byte[] buf, int off)
    Variant of `iscVaxInteger(byte[], int, int)` specifically for two-byte integers.
    Parameters:
      `buf` - byte array from which the integer is to be retrieved
      `off` - offset from which to start retrieving byte values
    Returns:
      integer value retrieved from the bytes
    See Also:
      - `iscVaxInteger(byte[], int, int)`
      - `iscVaxLong(byte[], int, int)`

  - ### encodeVaxInteger2WithoutLength

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

  - ### encodeVaxInteger2WithoutLength

    public static void encodeVaxInteger2WithoutLength(byte[] buf, int off, int val)
    Encodes an integer using two byte Vax encoding into `buf`, without length prefix.
    Parameters:
      `buf` - byte array of sufficient size
      `off` - offset to start writing
      `val` - value to encode
    Since:
      6.0.2

  - ### decodeVaxInteger2WithoutLength

    public static int decodeVaxInteger2WithoutLength(InputStream in) throws IOException
    Decodes an integer using two byte Vax encoding from an input stream, without length prefix.
    Parameters:
      `in` - input stream to read
    Returns:
      decoded value
    Throws:
      `IOException` - for errors reading from the stream, or if end-of-stream was reached before the full integer
    Since:
      6