ftp2me
Class LineReader

java.lang.Object
  extended by java.io.Reader
      extended by java.io.InputStreamReader
          extended by ftp2me.LineReader

public class LineReader
extends java.io.InputStreamReader

Can read a line from character streams. Uses only a single character "buffer". This is a faster, more memory-saving and simpler implementation of the BufferedReader, and implements only those methods vital for ftp2me, so it is not intended to be a drop-in replacement, or to be compatible with it by any means.


Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
LineReader(java.io.InputStream in)
          Creates a LineReader instance out of an InputStream
 
Method Summary
 void mark(int readLimit)
          This method does nothing, do not use it.
 boolean markSupported()
          We do not support mark(), so it returns constant false.
 int read()
          Reads one character from the stream.
 int read(char[] cbuf)
          Reads a character array from the stream.
 int read(char[] cbuf, int off, int len)
          Reads a character array from the stream.
 java.lang.String readLine()
          OK, this is the point.
 boolean ready()
          Returns true if there is at least one character that can be returned immediately by a read() operation (without blocking the thread).
 void reset()
          Again: mark not supported, so this should be used.
 long skip(long n)
          Read n characters from the stream an discard them.
 
Methods inherited from class java.io.InputStreamReader
close
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineReader

public LineReader(java.io.InputStream in)
Creates a LineReader instance out of an InputStream

Parameters:
in - InputStream from wich we read
Method Detail

markSupported

public boolean markSupported()
We do not support mark(), so it returns constant false.

Overrides:
markSupported in class java.io.InputStreamReader

mark

public void mark(int readLimit)
This method does nothing, do not use it.

Overrides:
mark in class java.io.InputStreamReader

read

public int read()
         throws java.io.IOException
Reads one character from the stream. Throws an exception when the underlying InputStreamReader.read() does.

Overrides:
read in class java.io.InputStreamReader
Throws:
java.io.IOException

read

public int read(char[] cbuf)
         throws java.io.IOException
Reads a character array from the stream. Throws an exception when the underlying InputStreamReader.read() does.

Overrides:
read in class java.io.Reader
Parameters:
cbuf - Array of characters to fill.
Throws:
java.io.IOException

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Reads a character array from the stream. Throws an exception when the underlying InputStreamReader.read() does.

Overrides:
read in class java.io.InputStreamReader
Parameters:
cbuf - Array of characters to fill (partially?).
off - Offset: first n characters in cbuf to be left alone
len - Read that many characters
Throws:
java.io.IOException

reset

public void reset()
           throws java.io.IOException
Again: mark not supported, so this should be used. If you do so, this method will blow an IOException into your face.

Overrides:
reset in class java.io.InputStreamReader
Throws:
java.io.IOException

skip

public long skip(long n)
          throws java.io.IOException
Read n characters from the stream an discard them.

Overrides:
skip in class java.io.InputStreamReader
Parameters:
n - Number of characters to discard
Throws:
java.io.IOException

ready

public boolean ready()
              throws java.io.IOException
Returns true if there is at least one character that can be returned immediately by a read() operation (without blocking the thread).

Overrides:
ready in class java.io.InputStreamReader
Throws:
java.io.IOException

readLine

public java.lang.String readLine()
                          throws java.io.IOException
OK, this is the point. This method reads a line from the underlying InputStream. It recognizes Dos, Max and Unix line endings automatically (thats why we need a one character "buffer").

Throws:
java.io.IOException