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 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 toparseShort(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 valueuShort
toout
.
-
-
-
Method Detail
-
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 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 valueuShort
toout
.- 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.
-
-