org.openuat.util
Class LineReaderWriter

java.lang.Object
  extended by org.openuat.util.LineReaderWriter

public class LineReaderWriter
extends java.lang.Object

This is a tiny helper class to provide readLine and println methods around InputStream and OutputStream. In contrast to BufferedReader and PrintWriter (which are not available on CDLC anyways), the implementations in this class are unbuffered, and reading a line therefore does not consume too many bytes from the underlying stream (as BufferedReader would do). This makes it possible to call readLine on an InputStream and then re-use it for binary transfers.

Since:
0.10
Version:
1.0
Author:
Rene Mayrhofer

Constructor Summary
LineReaderWriter()
           
 
Method Summary
static void println(java.io.OutputStream out, java.lang.String line)
          Print a line to an OutputStream, temporarily wrapping it in an OutputStreamWriter.
static void println(java.io.OutputStreamWriter out, java.lang.String line)
          Print a line to an OutputStreamWriter.
static java.lang.String readLine(java.io.InputStream in)
          just calls readLine(in, -1).
static java.lang.String readLine(java.io.InputStream in, int timeoutMs)
          Read a line from an InputStream (until a '\n' character is encountered).
static int readWithTimeout(java.io.InputStream in, int timeoutMs)
          If timeoutMs > 0, then this method first waits for a byte to become available in in before reading it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineReaderWriter

public LineReaderWriter()
Method Detail

readWithTimeout

public static int readWithTimeout(java.io.InputStream in,
                                  int timeoutMs)
                           throws java.io.IOException
If timeoutMs > 0, then this method first waits for a byte to become available in in before reading it. If none becomes available within timeoutMs, an IOException will be thrown.

Throws:
java.io.IOException

readLine

public static java.lang.String readLine(java.io.InputStream in,
                                        int timeoutMs)
                                 throws java.io.IOException
Read a line from an InputStream (until a '\n' character is encountered). This method blocks until the end of line or the end of stream (-1) is received or the timeout (in milliseconds) is reached.

Throws:
java.io.IOException

readLine

public static java.lang.String readLine(java.io.InputStream in)
                                 throws java.io.IOException
just calls readLine(in, -1).

Throws:
java.io.IOException

println

public static void println(java.io.OutputStream out,
                           java.lang.String line)
                    throws java.io.IOException
Print a line to an OutputStream, temporarily wrapping it in an OutputStreamWriter.

Throws:
java.io.IOException

println

public static void println(java.io.OutputStreamWriter out,
                           java.lang.String line)
                    throws java.io.IOException
Print a line to an OutputStreamWriter.

Throws:
java.io.IOException


2005-2006, Rene Mayrhofer.