Package nom.tam.util

Class ByteParser

java.lang.Object
nom.tam.util.ByteParser

@Deprecated public class ByteParser extends Object
Deprecated.
This class should not be exposed in the public API and is intended for internal use only in ASCII tables. Also, it may have overlapping functionality with other classes, which should probably be eliminated for simplicity's sake (and thus less chance of nasty bugs).
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.

See Also:
  • Constructor Details

    • ByteParser

      @Deprecated public ByteParser(byte[] input)
      Deprecated.
      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

    • getBoolean

      @Deprecated public boolean getBoolean() throws FormatException
      Deprecated.
      Returns the next boolean value from the current parse position.
      Returns:
      a boolean value from the beginning of the buffer.
      Throws:
      FormatException - if the double was in an unknown format
    • getBoolean

      @Deprecated public boolean getBoolean(int length) throws FormatException
      Deprecated.
      Returns the next double value from the current parse position, consuming at most the specified number of bytes from the input.
      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

      @Deprecated public byte[] getBuffer()
      Deprecated.
      Returns the underlying buffer to this parser.
      Returns:
      the buffer being used by the parser
    • getDouble

      @Deprecated public double getDouble() throws FormatException
      Deprecated.
      Returns the next long value from the current parse position, consuming at most the specified number of bytes from the input. 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

      @Deprecated public double getDouble(int length) throws FormatException
      Deprecated.
      Returns the next double value from the current parse position, consuming at most the specified number of bytes from the input.
      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

      @Deprecated public float getFloat() throws FormatException
      Deprecated.
      Returns the next float value from the current parse position.
      Returns:
      a floating point value from the buffer. (see getDouble(int())
      Throws:
      FormatException - if the float was in an unknown format
    • getFloat

      @Deprecated public float getFloat(int length) throws FormatException
      Deprecated.
      Returns the next float value from the current parse position, consuming at most the specified number of bytes from the input.
      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

      @Deprecated public int getInt() throws FormatException
      Deprecated.
      Returns the next in value from the current parse position.
      Returns:
      an integer at the beginning of the buffer
      Throws:
      FormatException - if the integer was in an unknown format
    • getInt

      @Deprecated public int getInt(int length) throws FormatException
      Deprecated.
      Returns the next int value from the current parse position, consuming at most the specified number of bytes from the input.
      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

      @Deprecated public long getLong(int length) throws FormatException
      Deprecated.
      Returns the next long value from the current parse position, consuming at most the specified number of bytes from the input.
      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

      @Deprecated public int getNumberLength()
      Deprecated.
      Returns the length of the previous string returned (that is the number that was parse last).
      Returns:
      the number of characters used to parse the previous number (or the length of the previous String returned).
    • getOffset

      @Deprecated public int getOffset()
      Deprecated.
      Get the current offset.
      Returns:
      The current offset within the buffer.
    • getString

      @Deprecated public String getString(int length)
      Deprecated.
      Returns the specified number of bytes as a string.
      Parameters:
      length - The length of the string.
      Returns:
      a string.
    • setBuffer

      @Deprecated public void setBuffer(byte[] buf)
      Deprecated.
      Set the buffer for the parser.
      Parameters:
      buf - buffer to set
    • setOffset

      @Deprecated public void setOffset(int offset)
      Deprecated.
      Set the offset into the array.
      Parameters:
      offset - The desired offset from the beginning of the array.
    • skip

      @Deprecated public void skip(int nBytes)
      Deprecated.
      Skip bytes in the buffer.
      Parameters:
      nBytes - number of bytes to skip
    • skipWhite

      @Deprecated public int skipWhite(int length)
      Deprecated.
      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'