Class ScanfReader

java.lang.Object
java.io.Reader
org.cip4.jdflib.cformat.ScanfReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable
Direct Known Subclasses:
SScanf

@Deprecated public class ScanfReader extends Reader
Deprecated.
use Scanner
A Reader which implements C scanf functionality. Once created, an application can read various primitive types from the underlying stream using various scan methods that implement scanf type input formatting.

There are scan methods to read float, double, long, int, char, char[], and String. The methods take as an argument either a format string, a pre-allocated ScanfFormat object which is created from a format string, or no argument (implying a default format). The format string is modeled after that accepted by the C scanf() methodName, and is described in the documentation for the class ScanfFormat.

Because Java does not permit variable-length argument lists, only one primitive type may be returned per method, and the format used may contain only one conversion specification (which must be appropriate to the type being scanned).

Input errors in the underlying Reader result in a java.io.IOException being thrown, while a java.io.EOFException is thrown if the end of input is reached before the scan can complete successfully. If the input does not match the specified format, then a ScanfMatchException is thrown. In the event of a match error, scanning stops at the first character from which it can be determined that the match will fail. This character is remembered by the stream (see the discussion of the look-ahead character, below) and will be the first character seen by the next scan or read method which is called. Finally, an invalid format string (or ScanfFormat object) will trigger an InvalidArgumentException.

The class keeps track of the current line number (accessible with the methods getLineNumber and setLineNumber), as well as the number of characters which have been consumed (accesible with the methods getCharNumber and setCharNumber).

The class usually keeps one character of look-ahead which has been read from the underlying reader but not yet consumed by any scan method. If the underlying reader is used later in some other capacity, this look-ahead character may have to be taken into account. If a look-ahead character is actually being stored, the lookAheadCharValid method will return true, and the look-ahead character itself can then be obtained using the getLookAheadChar method. The look-ahead character can be cleared using the clearLookAheadChar method.

  • Field Summary

    Fields inherited from class java.io.Reader

    lock
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
    Create a new ScanfReader from the given reader.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deprecated.
    Clears the look-ahead character.
    void
    Deprecated.
    Closes the stream.
    int
    Deprecated.
    Gets the current character number (equal to the number of characters that have been consumed by the stream).
    int
    Deprecated.
    Gets the current line number.
    int
    Deprecated.
    Returns the look-ahead character.
    boolean
    Deprecated.
    Returns whether or not a look-ahead character is currently begin stored.
    int
    read(char[] cbuf, int off, int len)
    Deprecated.
    Reads characters into a portion of a character array.
    char
    Deprecated.
    Scan and return a single character, using the default format string "%c".
    char
    Deprecated.
    Scan and return a single character.
    char
    Deprecated.
    Scan and return a single character, using a pre-allocated ScanfFormat object.
    char[]
    scanChars(int n)
    Deprecated.
    Scan and return a character array, using the default format string "%c", with the field width (number of characters to read) supplanted by the argument n.
    char[]
    Deprecated.
    Scan and return a character array, whose size is determined by the field width specified in the format string (with a default width of 1 being assumed if no width is specified).
    char[]
    Deprecated.
    Scan and return a character array, using a pre-allocated ScanfFormat object.
    long
    Deprecated.
    Scan and return a signed decimal (long) integer, using the default format string "%d".
    long
    Deprecated.
    Scan and return a signed decimal (long) integer.
    long
    Deprecated.
    Scan and return a signed decimal (long) integer, using a pre-allocated ScanfFormat object.
    double
    Deprecated.
    Scan and return a double, using the default format string "%f".
    double
    Deprecated.
    Scan and return a double.
    double
    Deprecated.
    Scan and return a double, using a pre-allocated ScanfFormat object.
    float
    Deprecated.
    Scan and return a float, using the default format string "%f".
    float
    Deprecated.
    Scan and return a float.
    float
    Deprecated.
    Scan and return a float, using a pre-allocated ScanfFormat object.
    long
    Deprecated.
    Scan and return a hex (long) integer, using the default format string "%x".
    long
    Deprecated.
    Scan and return a hex (long) integer.
    long
    Deprecated.
    Scan and return a hex (long) integer, using a pre-allocated ScanfFormat object.
    int
    Deprecated.
    Scan and return a signed integer, using the default format string "%i".
    int
    Deprecated.
    Scan and return a signed integer.
    int
    Deprecated.
    Scan and return a signed integer, using a pre-allocated ScanfFormat object.
    long
    Deprecated.
    Scan and return a signed (long) integer, using the default format string "%i".
    long
    Deprecated.
    Scan and return a signed (long) integer.
    long
    Deprecated.
    Scan and return a signed (long) integer, using a pre-allocated ScanfFormat object.
    long
    Deprecated.
    Scan and return an octal (long) integer, using the default format string "%o".
    long
    Deprecated.
    Scan and return an octal (long) integer.
    long
    Deprecated.
    Scan and return an octal (long) integer, using a pre-allocated ScanfFormat object.
    Deprecated.
    Scan and return a String, using the default format string "%s".
    Deprecated.
    Scan and return a String.
    Deprecated.
    Scan and return a String, using a pre-allocated ScanfFormat object.
    void
    Deprecated.
    Sets the current character number.
    void
    Deprecated.
    Sets the current line number.
    boolean
    Deprecated.
    White spaces are skipped at the beginning of a line if flag is true otherwise spaces are counted as valid characters.
    void
    useCstandard(boolean flag)
    Deprecated.
    White spaces are skipped at the beginning of a line if flag is true otherwise spaces are counted as valid characters.

    Methods inherited from class java.io.Reader

    mark, markSupported, nullReader, read, read, read, ready, reset, skip, transferTo

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait