import java.io.*;
public class LineReader
{
InputStream is = null;
Reader ir = null;
char[] lineTerminator = System.getProperty ("line.separator").
toCharArray ();
public LineReader (InputStream is)
{
this.is = is;
}
public LineReader (Reader ir)
{
this.ir = ir;
}
private int read ()
throws IOException
{
if (is != null)
return (is.read ());
else if (ir != null)
return (ir.read ());
else
throw new IllegalStateException ();
}
public String readLine ()
throws IOException
{
StringBuffer buf = new StringBuffer ();
char[] save = new char[lineTerminator.length];
int pos = 0;
int ch = read ();
boolean done = false;
if (ch < 0)
return (null);
do
{
if (ch == lineTerminator[pos])
{
save[pos] = (char) ch;
pos++;
}
else
{
if (pos + 1 < lineTerminator.length &&
ch == lineTerminator[pos + 1])
pos += 2;
else
{
if (pos > 0)
{
buf.append (save, 0, pos);
pos = 0;
}
buf.append ((char) ch);
}
}
done = pos >= lineTerminator.length;
if (!done)
ch = read ();
if (ch < 0)
done = true;
} while (!done);
return (new String (buf));
}
}