|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnom.tam.util.ByteParser
public class ByteParser
This class provides routines for efficient parsing of data stored in a byte array. This routine is optimized (in theory at least!) for efficiency rather than accuracy. The values read in for doubles or floats may differ in the last bit or so from the standard input utilities, especially in the case where a float is specified as a very long string of digits (substantially longer than the precision of the type).
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 Summary | |
---|---|
ByteParser(byte[] input)
Construct a parser. |
Method Summary | |
---|---|
boolean |
getBoolean()
Get a boolean value from the beginning of the buffer |
boolean |
getBoolean(int length)
Get a boolean value from a specified region of the buffer |
byte[] |
getBuffer()
Get the buffer being used by the parser |
double |
getDouble()
Read in the buffer until a double is read. |
double |
getDouble(int length)
Look for a double in the buffer. |
float |
getFloat()
Get a floating point value from the buffer. |
float |
getFloat(int length)
Get a floating point value in a region of the buffer |
int |
getInt()
Look for an integer at the beginning of the buffer |
int |
getInt(int length)
Convert a region of the buffer to an integer |
long |
getLong(int length)
Look for a long in a specified region of the buffer |
int |
getNumberLength()
Get the number of characters used to parse the previous number (or the length of the previous String returned). |
int |
getOffset()
Get the current offset |
java.lang.String |
getString(int length)
Get a string |
void |
setBuffer(byte[] buf)
Set the buffer for the parser |
void |
setFillFields(boolean flag)
Do we require a field to completely fill up the specified length (with optional leading and trailing white space. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
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.Method Detail |
---|
public void setBuffer(byte[] buf)
public byte[] getBuffer()
public void setOffset(int offset)
offset
- The desired offset from the beginning
of the array.public void setFillFields(boolean flag)
flag
- Is filling required?public int getOffset()
public int getNumberLength()
public double getDouble() throws FormatException
FormatException
public 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
public float getFloat() throws FormatException
FormatException
public float getFloat(int length) throws FormatException
FormatException
public int getInt(int length) throws FormatException
FormatException
public int getInt() throws FormatException
FormatException
public long getLong(int length) throws FormatException
FormatException
public java.lang.String getString(int length)
length
- The length of the string.public boolean getBoolean() throws FormatException
FormatException
public boolean getBoolean(int length) throws FormatException
FormatException
public void skip(int nBytes)
public int skipWhite(int length)
length
- The maximum number of characters to skip.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |