m865.io
Class MySystem

java.lang.Object
  extended by m865.io.MySystem

public class MySystem
extends java.lang.Object

The MySystem class mimics the features of stdin, stdout, and stderr, enabling these IO streams to be redirected to files.


Field Summary
static java.io.PrintWriter defaultErr
          The defaul Error stream corresponds to the Unix stderr.
static java.io.InputStreamReader defaultIn
          The default Input stream corresponding to the Unix stdin.
static java.io.PrintWriter defaultOut
          The default Output stream corresponding to the Unix stdout.
 
Constructor Summary
MySystem()
           
 
Method Summary
static void main(java.lang.String[] args)
           
static java.lang.String paddedFormat(long k, int space)
          Converts an integer to a string with enough leading blanks to fill a space of the specified size.
static void setDefaultErr()
          Redirect the default Error stream to System.err.
static void setDefaultErr(java.lang.String fileName)
          Redirect the default Error stream to the specified file.
static void setDefaultIn()
          Redirect the default Input stream to System.in.
static void setDefaultIn(java.lang.String fileName)
          Redirects the default Input stream to the specified file.
static void setDefaultOut()
          Redirect the default Output stream to System.out.
static void setDefaultOut(java.lang.String fileName)
          Redirect the default Output stream to the specified file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultIn

public static java.io.InputStreamReader defaultIn
The default Input stream corresponding to the Unix stdin.


defaultOut

public static java.io.PrintWriter defaultOut
The default Output stream corresponding to the Unix stdout.


defaultErr

public static java.io.PrintWriter defaultErr
The defaul Error stream corresponds to the Unix stderr.

Constructor Detail

MySystem

public MySystem()
Method Detail

setDefaultIn

public static void setDefaultIn(java.lang.String fileName)
                         throws java.io.IOException
Redirects the default Input stream to the specified file.

Parameters:
fileName - the name of the input file.
Throws:
java.io.IOException - in case of a file handling error.

setDefaultIn

public static void setDefaultIn()
Redirect the default Input stream to System.in.


setDefaultOut

public static void setDefaultOut(java.lang.String fileName)
                          throws java.io.IOException
Redirect the default Output stream to the specified file.

Parameters:
fileName - the name of the output file.
Throws:
java.io.IOException - in case of a file handling error.

setDefaultOut

public static void setDefaultOut()
Redirect the default Output stream to System.out.


setDefaultErr

public static void setDefaultErr(java.lang.String fileName)
                          throws java.io.IOException
Redirect the default Error stream to the specified file.

Parameters:
fileName - the name of the error file.
Throws:
java.io.IOException - in case of a file handling error.

setDefaultErr

public static void setDefaultErr()
Redirect the default Error stream to System.err.


paddedFormat

public static java.lang.String paddedFormat(long k,
                                            int space)
Converts an integer to a string with enough leading blanks to fill a space of the specified size.

Parameters:
k - the long integer to be formatted
space - the size of the space to be filled
Returns:
a formatted string with the integer right justified in the specified space.

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException