Sharkysoft home

lava.io
Class IoToolbox

java.lang.Object
  |
  +--lava.io.IoToolbox

public final class IoToolbox
extends java.lang.Object

Miscellaneous I/O functions.

Details: This class contains a variety of miscellaneous I/O-related utility functions and definitions.

Changes:

2000.12.18
Added preloadStream (Reader, int).

Since:
1998.10.11
Version:
2000.12.18
Author:
Sharky

Constructor Summary
IoToolbox()
           
 
Method Summary
static byte[] computeStreamDigest(java.io.InputStream is, java.lang.String algo)
          Computes a message digest from a stream.
static java.io.LineNumberReader getConfigFileReader(java.lang.String name)
          Returns reader suitable for parsing config files.
static java.io.BufferedReader getStdinReader()
          Creates reader for stdin.
static int peek(java.io.PushbackReader in)
           
static java.lang.String preloadStream(java.io.Reader reader, int size)
          Loads entire stream into string.
static void printLines(java.lang.String[] lines)
          Prints lines.
static java.lang.String readLine(java.io.Reader r)
           
static void unread(java.io.PushbackReader in, java.lang.String s)
          Pushes string onto PushbackReader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IoToolbox

public IoToolbox()
Method Detail

computeStreamDigest

public static byte[] computeStreamDigest(java.io.InputStream is,
                                         java.lang.String algo)
                                  throws java.io.IOException
Computes a message digest from a stream.

Details: computeStreamDigest computes a message digest for the supplied input stream, closes the stream, and then returns the digest.

The digest name must be one of the standard digest names provided in the Java Security API.

Parameters:
is - the input stream
algo - the digest algorithm
Returns:
the digest
Throws:
java.io.IOException - if an I/O error occurs
Since:
1999.10.21

unread

public static void unread(java.io.PushbackReader in,
                          java.lang.String s)
                   throws java.io.IOException
Pushes string onto PushbackReader.

Details: unread pushes the given string (s) onto the given PushbackReader (in).

Parameters:
in - the PushbackReader
s - the string
Throws:
java.io.IOException - if an I/O error occurs
Since:
2000.06.01

peek

public static int peek(java.io.PushbackReader in)
                throws java.io.IOException

readLine

public static java.lang.String readLine(java.io.Reader r)
                                 throws java.io.IOException

printLines

public static void printLines(java.lang.String[] lines)
Prints lines.

Details: printLines calls System.out . println() on each of the strings in the given array (lines). (For example, you can use this to print a program usage summary when your command line program is run without arguments.)

Parameters:
lines - lines to print
Since:
2000.09.24

getConfigFileReader

public static java.io.LineNumberReader getConfigFileReader(java.lang.String name)
                                                    throws java.io.IOException
Returns reader suitable for parsing config files.

Details: getConfigFileReader returns a LineNumberReader that reads from configuration file whose path is (name). The returned reader automatically trims away Unix-style hashed comments.

Parameters:
name - path to config file
Returns:
config file reader
Throws:
java.io.IOException - if an I/O error occurs
Since:
2000.11.08

getStdinReader

public static java.io.BufferedReader getStdinReader()
                                             throws java.io.IOException
Creates reader for stdin.

Details: getStdinReader returns a BufferedReader attached to System.in.

Returns:
the reader
Throws:
java.io.IOException - if an I/O error occurs
Since:
2000.11.08

preloadStream

public static java.lang.String preloadStream(java.io.Reader reader,
                                             int size)
                                      throws java.io.IOException
Loads entire stream into string.

Details: preloadStream loads the entire given stream (reader) into a string and returns it. The size parameter offers a hint to this implementation about the total length of the stream, and may be set to 0 if the length of the stream is not known.

Parameters:
reader - the stream
size - estimated buffer size needed
Returns:
the string containing the contents of the stream
Throws:
java.io.IOException - if an I/O error occurs
Since:
2000.12.19

Sharkysoft home