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 PrimitivesParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byteparseByte(byte[] b, int off)Parse a single byte in the provided bytes.static intparseInt(byte[] b, int off)Parse an integer primitive type in the provided bytes.static longparseLong(byte[] b, int off)Parse a long primitive type in the provided bytes.static shortparseShort(byte[] b, int off)Parse a short primitive type in the provided bytes.static intparseUnsignedShort(byte[] b, int off)Equivalent toparseShort(byte[], int)except the 2 bytes are treated as an unsigned value (and thus returned as an into to avoid overflow).static voidwriteUnsignedShort(DataOutput out, int uShort)Writes 2 bytes containing the unsigned valueuShorttoout.
-
-
-
Method Detail
-
parseLong
public static long parseLong(byte[] b, int off) throws ParseExceptionParse 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 ParseExceptionParse 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 toparseShort(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 valueuShorttoout.- 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.
-
-