Class ByteParser
The get methods generally are available with or without a length parameter specified. When a length parameter is specified only the bytes with the specified range from the current offset will be search for the number. If no length is specified, the entire buffer from the current offset will be searched.
The getString method returns a string with leading and trailing white space left intact. For all other get calls, leading white space is ignored. If fillFields is set, then the get methods check that only white space follows valid data and a FormatException is thrown if that is not the case. If fillFields is not set and valid data is found, then the methods return having read as much as possible. E.g., for the sequence "T123.258E13", a getBoolean, getInteger and getFloat call would return true, 123, and 2.58e12 when called in succession.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final doubleprivate booleanDid we find a sign last time we checked?private static final intprivate static final byte[]private static final intprivate static final byte[]private byte[]Array being parsedprivate static final intprivate static final byte[]private static final byte[]private static final intThe underlying number base used in this class.private static final doubleThe underlying number base used in this class as a double value.private intLength of last parsed valueprivate intCurrent offset into input. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate intFind the sign for a number .private doublegetBareInteger(int length) Get the integer value starting at the current position.booleanbooleangetBoolean(int length) byte[]doubleRead in the buffer until a double is read.doublegetDouble(int length) floatgetFloat()floatgetFloat(int length) intgetInt()intgetInt(int length) longgetLong(int length) intintGet the current offset.getString(int length) private booleanisCaseInsensitiv(int length, int constantLength, byte[] lowerConstant, byte[] upperConstant) voidsetBuffer(byte[] buf) Set the buffer for the parser.voidsetOffset(int offset) Set the offset into the array.voidskip(int nBytes) Skip bytes in the buffer.intskipWhite(int length) Skip white space.
-
Field Details
-
EXPONENT_DENORMALISATION_CORR_LIMIT
private static final int EXPONENT_DENORMALISATION_CORR_LIMIT- See Also:
-
EXPONENT_DENORMALISATION_FACTOR
private static final double EXPONENT_DENORMALISATION_FACTOR- See Also:
-
INFINITY_LOWER
private static final byte[] INFINITY_LOWER -
INFINITY_UPPER
private static final byte[] INFINITY_UPPER -
INFINITY_LENGTH
private static final int INFINITY_LENGTH -
INFINITY_SHORTCUT_LENGTH
private static final int INFINITY_SHORTCUT_LENGTH- See Also:
-
NOT_A_NUMBER_LOWER
private static final byte[] NOT_A_NUMBER_LOWER -
NOT_A_NUMBER_UPPER
private static final byte[] NOT_A_NUMBER_UPPER -
NOT_A_NUMBER_LENGTH
private static final int NOT_A_NUMBER_LENGTH -
NUMBER_BASE
private static final int NUMBER_BASEThe underlying number base used in this class.- See Also:
-
NUMBER_BASE_DOUBLE
private static final double NUMBER_BASE_DOUBLEThe underlying number base used in this class as a double value.- See Also:
-
foundSign
private boolean foundSignDid we find a sign last time we checked? -
input
private byte[] inputArray being parsed -
numberLength
private int numberLengthLength of last parsed value -
offset
private int offsetCurrent offset into input.
-
-
Constructor Details
-
ByteParser
public ByteParser(byte[] input) Construct a parser.- Parameters:
input- The byte array to be parsed. Note that the array can be re-used by refilling its contents and resetting the offset.
-
-
Method Details
-
checkSign
private int checkSign()Find the sign for a number . This routine looks for a sign (+/-) at the current location and return +1/-1 if one is found, or +1 if not. The foundSign boolean is set if a sign is found and offset is incremented. -
getBareInteger
private double getBareInteger(int length) Get the integer value starting at the current position. This routine returns a double rather than an int/long to enable it to read very long integers (with reduced precision) such as 111111111111111111111111111111111111111111. Note that this routine does set numberLength.- Parameters:
length- The maximum number of characters to use.
-
getBoolean
- Returns:
- a boolean value from the beginning of the buffer.
- Throws:
FormatException- if the double was in an unknown format
-
getBoolean
- Parameters:
length- The maximum number of characters used to parse this boolean.- Returns:
- a boolean value from a specified region of the buffer
- Throws:
FormatException- if the double was in an unknown format
-
getBuffer
public byte[] getBuffer()- Returns:
- the buffer being used by the parser
-
getDouble
Read in the buffer until a double is read. This will read the entire buffer if fillFields is set.- Returns:
- The value found.
- Throws:
FormatException- if the double was in an unknown format
-
getDouble
- Parameters:
length- The maximum number of characters used to parse this number. If fillFields is specified then exactly only whitespace may follow a valid double value.- Returns:
- a parsed double from the buffer. Leading spaces are ignored.
- Throws:
FormatException- if the double was in an unknown format
-
getFloat
- Returns:
- a floating point value from the buffer. (see getDouble(int())
- Throws:
FormatException- if the float was in an unknown format
-
getFloat
- Parameters:
length- The maximum number of characters used to parse this float.- Returns:
- a floating point value in a region of the buffer
- Throws:
FormatException- if the float was in an unknown format
-
getInt
- Returns:
- an integer at the beginning of the buffer
- Throws:
FormatException- if the integer was in an unknown format
-
getInt
- Parameters:
length- The maximum number of characters used to parse this integer. @throws FormatException if the integer was in an unknown format- Returns:
- a region of the buffer to an integer
- Throws:
FormatException- if the integer was in an unknown format
-
getLong
- Parameters:
length- The maximum number of characters used to parse this long.- Returns:
- a long in a specified region of the buffer
- Throws:
FormatException- if the long was in an unknown format
-
getNumberLength
public int getNumberLength()- Returns:
- the number of characters used to parse the previous number (or the length of the previous String returned).
-
getOffset
public int getOffset()Get the current offset.- Returns:
- The current offset within the buffer.
-
getString
- Parameters:
length- The length of the string.- Returns:
- a string.
-
isCaseInsensitiv
private boolean isCaseInsensitiv(int length, int constantLength, byte[] lowerConstant, byte[] upperConstant) -
setBuffer
public void setBuffer(byte[] buf) Set the buffer for the parser.- Parameters:
buf- buffer to set
-
setOffset
public void setOffset(int offset) Set the offset into the array.- Parameters:
offset- The desired offset from the beginning of the array.
-
skip
public void skip(int nBytes) Skip bytes in the buffer.- Parameters:
nBytes- number of bytes to skip
-
skipWhite
public int skipWhite(int length) Skip white space. This routine skips with space in the input .- Parameters:
length- The maximum number of characters to skip.- Returns:
- the number of character skipped. White space is defined as ' ', '\t', '\n' or '\r'
-