public class ByteParser extends Object
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.
Constructor and Description |
---|
ByteParser(byte[] input)
Construct a parser.
|
Modifier and Type | Method and Description |
---|---|
boolean |
getBoolean() |
boolean |
getBoolean(int length) |
byte[] |
getBuffer() |
double |
getDouble()
Read in the buffer until a double is read.
|
double |
getDouble(int length) |
float |
getFloat() |
float |
getFloat(int length) |
int |
getInt() |
int |
getInt(int length) |
long |
getLong(int length) |
int |
getNumberLength() |
int |
getOffset()
Get the current offset.
|
String |
getString(int length) |
void |
setBuffer(byte[] buf)
Set the buffer for the parser.
|
void |
setOffset(int offset)
Set the offset into the array.
|
void |
skip(int nBytes)
Skip bytes in the buffer.
|
int |
skipWhite(int length)
Skip white space.
|
public ByteParser(byte[] input)
input
- The byte array to be parsed. Note that the array can be
re-used by refilling its contents and resetting the offset.public boolean getBoolean() throws FormatException
FormatException
- if the double was in an unknown formatpublic boolean getBoolean(int length) throws FormatException
length
- The maximum number of characters used to parse this boolean.FormatException
- if the double was in an unknown formatpublic byte[] getBuffer()
public double getDouble() throws FormatException
FormatException
- if the double was in an unknown formatpublic double getDouble(int length) throws FormatException
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.FormatException
- if the double was in an unknown formatpublic float getFloat() throws FormatException
FormatException
- if the float was in an unknown formatpublic float getFloat(int length) throws FormatException
length
- The maximum number of characters used to parse this float.FormatException
- if the float was in an unknown formatpublic int getInt() throws FormatException
FormatException
- if the integer was in an unknown formatpublic int getInt(int length) throws FormatException
length
- The maximum number of characters used to parse this integer. @throws
FormatException if the integer was in an unknown formatFormatException
- if the integer was in an unknown formatpublic long getLong(int length) throws FormatException
length
- The maximum number of characters used to parse this long.FormatException
- if the long was in an unknown formatpublic int getNumberLength()
public int getOffset()
public String getString(int length)
length
- The length of the string.public void setBuffer(byte[] buf)
buf
- buffer to setpublic void setOffset(int offset)
offset
- The desired offset from the beginning of the array.public void skip(int nBytes)
nBytes
- number of bytes to skippublic int skipWhite(int length)
length
- The maximum number of characters to skip.Copyright © 1996–2016 nom-tam-fits. All rights reserved.