au.com.zip.cs
Class IO

java.lang.Object
  extended by au.com.zip.cs.IO

public final class IO
extends Object

Assorted I/O convenience routines.

Author:
Cameron Simpson <cs@zip.com.au> 2mar2002

Constructor Summary
IO()
           
 
Method Summary
static String getContLine(LineStackReader r)
          Read a line and all subsequent lines commencing with a space or tab.
static String getSloshLine(BufferedReader r)
          Read a slosh ('\\') extended line from a BufferedReader, discarding the sloshes.
static String getSloshLine(BufferedReader r, boolean keepSlosh)
          Read a slosh ('\\') extended line from a BufferedReader, optionally discarding the sloshes.
static int probe(PushbackReader r)
          Return the next characters which would come from a PushbackReader, which may be EOF.
static StringBuffer readAll(Reader r)
          Read all the remaining characters from a Reader and return them in a single StringBuffer.
static char readChar(Reader r)
          Just like Reader.read() except that EOF is an exception and so we can return a char.
static int readHex1(Reader r)
          Read a single hexadecimal numeral from a Reader and return its hex value.
static int readHex2(Reader r)
          Read two hexadecimal numerals from a Reader and return their value.
static int readHex4(Reader r)
          Read four hexadecimal numerals from a Reader and return their value.
static StringBuffer readTo(PushbackReader r, String delims)
          Read characters from a PushbackReader until one of the delimiters listed in the String delims is reached.
static StringBuffer readTo(PushbackReader r, String delims, StringBuffer b)
          Read characters from a PushbackReader until one of the delimiters listed in the String delims is reached, appending to the supplied StringBuffer.
static StringBuffer readWord(PushbackReader r)
          Read an identifier from a PushbackReader.
static void skipWhite(PushbackReader r)
          Skip past any whitespace characters at the start of a PushbackReader.
static void unreadChar(PushbackReader r, char ch)
          Just like PushbackReader.unread(int) except that it only takes chars.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IO

public IO()
Method Detail

readChar

public static final char readChar(Reader r)
                           throws IOException
Just like Reader.read() except that EOF is an exception and so we can return a char.

Parameters:
r - the Reader from which to read
Throws:
IOException

unreadChar

public static final void unreadChar(PushbackReader r,
                                    char ch)
                             throws IOException
Just like PushbackReader.unread(int) except that it only takes chars. It seems that unread(int), which takes an int, transmutes EOF (-1) into 65535, and so although it permits pushing back EOF, this breaks the stream.

Parameters:
r - the Reader from which to read
ch - the char to push back
Throws:
IOException

probe

public static final int probe(PushbackReader r)
                       throws IOException
Return the next characters which would come from a PushbackReader, which may be EOF.

Parameters:
r - the PushbackReader
Returns:
the next character
Throws:
IOException

readTo

public static final StringBuffer readTo(PushbackReader r,
                                        String delims)
                                 throws IOException
Read characters from a PushbackReader until one of the delimiters listed in the String delims is reached. The delimiter is left on the Reader.

Parameters:
r - a PushbackReader from which to read
delims - a list of stop characters
Returns:
a StringBuffer containing the characters read
Throws:
IOException

readTo

public static final StringBuffer readTo(PushbackReader r,
                                        String delims,
                                        StringBuffer b)
                                 throws IOException
Read characters from a PushbackReader until one of the delimiters listed in the String delims is reached, appending to the supplied StringBuffer. A new StringBuffer is allocated if the supplied one is null. The delimiter is left on the Reader.

Parameters:
r - a PushbackReader from which to read
delims - a list of stop characters
b - the StringBuffer
Returns:
the StringBuffer containing the characters read
Throws:
IOException

readWord

public static final StringBuffer readWord(PushbackReader r)
                                   throws IOException
Read an identifier from a PushbackReader.

Parameters:
r - the stream from which to read
Returns:
a StringBuffer holding the word, if any
Throws:
IOException

readHex1

public static final int readHex1(Reader r)
                          throws IOException,
                                 ParseException
Read a single hexadecimal numeral from a Reader and return its hex value.

Parameters:
r - the stream from which to read
Returns:
the value of the numeral
Throws:
ParseException - thrown when a hexadecimal numeral was found
IOException

readHex2

public static final int readHex2(Reader r)
                          throws IOException,
                                 ParseException
Read two hexadecimal numerals from a Reader and return their value.

Parameters:
r - the stream from which to read
Returns:
the value of the numerals
Throws:
ParseException - thrown when less than two hexadecimal numerals were found
IOException

readHex4

public static final int readHex4(Reader r)
                          throws IOException,
                                 ParseException
Read four hexadecimal numerals from a Reader and return their value.

Parameters:
r - the stream from which to read
Returns:
the value of the numerals
Throws:
ParseException - thrown when less than four hexadecimal numerals were found
IOException

skipWhite

public static void skipWhite(PushbackReader r)
                      throws IOException
Skip past any whitespace characters at the start of a PushbackReader.

Parameters:
r - the stream from which to read
Throws:
IOException

getSloshLine

public static String getSloshLine(BufferedReader r)
                           throws IOException
Read a slosh ('\\') extended line from a BufferedReader, discarding the sloshes.

Parameters:
r - the stream from which to read
Returns:
the multiline, or null at EOF
Throws:
IOException

getSloshLine

public static String getSloshLine(BufferedReader r,
                                  boolean keepSlosh)
                           throws IOException
Read a slosh ('\\') extended line from a BufferedReader, optionally discarding the sloshes. The trailing newline of the last (unsloshed) line collected is discarded.

Parameters:
r - the stream from which to read
keepSlosh - whether to keep the sloshes
Returns:
the multiline, or null at EOF
Throws:
IOException

getContLine

public static String getContLine(LineStackReader r)
                          throws IOException
Read a line and all subsequent lines commencing with a space or tab.

Parameters:
r - the LineStackReader from which to read lines
Throws:
IOException

readAll

public static StringBuffer readAll(Reader r)
                            throws IOException
Read all the remaining characters from a Reader and return them in a single StringBuffer.

Parameters:
r - the stream from which to read
Returns:
a StringBuffer holding the data
Throws:
IOException