public class PrimitivesParser extends Object
byte, short, int, long
) in
Java from a byte array.Constructor and Description |
---|
PrimitivesParser() |
Modifier and Type | Method and 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 . |
public static long parseLong(byte[] b, int off) throws ParseException
If successful, it returns the value of the parsed long type. On failure, it throws a parse exception.
b
- the byte array to parse.off
- the offset in the byte array to use when parsing.ParseException
- if there are not sufficient bytes.public static int parseInt(byte[] b, int off) throws ParseException
If successful, it returns the value of the parsed integer type. On failure, it throws a parse exception.
b
- the byte array to parse.off
- the offset in the byte array to use when parsing.ParseException
- if there are not sufficient bytes.public static short parseShort(byte[] b, int off)
If successful, it returns the value of the parsed short type. On failure, it throws a parse exception.
b
- the byte array to parse.off
- the offset in the byte array to use when parsing.ParseException
- if there are not sufficient bytes.public static int parseUnsignedShort(byte[] b, int off)
parseShort(byte[], int)
except the 2 bytes are treated as an unsigned
value (and thus returned as an into to avoid overflow).public static void writeUnsignedShort(DataOutput out, int uShort) throws IOException
uShort
to out
.IOException
public static byte parseByte(byte[] b, int off)
If successful, it returns the value of the parsed byte. On failure, it throws a parse exception.
b
- the byte array to parse.off
- the offset in the byte array to use when parsing.ParseException
- if there are not sufficient bytes.Copyright © 2023. All rights reserved.