Class PrimitivesParser

java.lang.Object
com.amazonaws.encryptionsdk.internal.PrimitivesParser

public class PrimitivesParser extends Object
This class implements methods for parsing the primitives ( byte, short, int, long) in Java from a byte array.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte
    parseByte​(byte[] b, int off)
    Parse a single byte in the provided bytes.
    static int
    parseInt​(byte[] b, int off)
    Parse an integer primitive type in the provided bytes.
    static long
    parseLong​(byte[] b, int off)
    Parse a long primitive type in the provided bytes.
    static short
    parseShort​(byte[] b, int off)
    Parse a short primitive type in the provided bytes.
    static int
    parseUnsignedShort​(byte[] b, int off)
    Equivalent to parseShort(byte[], int) except the 2 bytes are treated as an unsigned value (and thus returned as an into to avoid overflow).
    static void
    writeUnsignedShort​(DataOutput out, int uShort)
    Writes 2 bytes containing the unsigned value uShort to out.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PrimitivesParser

      public PrimitivesParser()
  • Method Details

    • parseLong

      public static long parseLong(byte[] b, int off) throws ParseException
      Parse a long primitive type in the provided bytes. It looks for 8 bytes in the provided bytes starting at the specified off.

      If successful, it returns the value of the parsed long type. On failure, it throws a parse exception.

      Parameters:
      b - the byte array to parse.
      off - the offset in the byte array to use when parsing.
      Returns:
      the parsed long value.
      Throws:
      ParseException - if there are not sufficient bytes.
    • parseInt

      public static int parseInt(byte[] b, int off) throws ParseException
      Parse an integer primitive type in the provided bytes. It looks for 4 bytes in the provided bytes starting at the specified off.

      If successful, it returns the value of the parsed integer type. On failure, it throws a parse exception.

      Parameters:
      b - the byte array to parse.
      off - the offset in the byte array to use when parsing.
      Returns:
      the parsed integer value.
      Throws:
      ParseException - if there are not sufficient bytes.
    • parseShort

      public static short parseShort(byte[] b, int off)
      Parse a short primitive type in the provided bytes. It looks for 2 bytes in the provided bytes starting at the specified off.

      If successful, it returns the value of the parsed short type. On failure, it throws a parse exception.

      Parameters:
      b - the byte array to parse.
      off - the offset in the byte array to use when parsing.
      Returns:
      the parsed short value.
      Throws:
      ParseException - if there are not sufficient bytes.
    • parseUnsignedShort

      public static int parseUnsignedShort(byte[] b, int off)
      Equivalent to parseShort(byte[], int) except the 2 bytes are treated as an unsigned value (and thus returned as an into to avoid overflow).
    • writeUnsignedShort

      public static void writeUnsignedShort(DataOutput out, int uShort) throws IOException
      Writes 2 bytes containing the unsigned value uShort to out.
      Throws:
      IOException
    • parseByte

      public static byte parseByte(byte[] b, int off)
      Parse a single byte in the provided bytes. It looks for a byte in the provided bytes starting at the specified off.

      If successful, it returns the value of the parsed byte. On failure, it throws a parse exception.

      Parameters:
      b - the byte array to parse.
      off - the offset in the byte array to use when parsing.
      Returns:
      the parsed byte value.
      Throws:
      ParseException - if there are not sufficient bytes.