public class LineReader
extends java.lang.Object
Here's a sample:
LineReader reader = new LineReader(new File("text.txt",File.READ_WRITE)); String line; while ((line = reader.readLine()) != null) { ... do whatever you want with the line. }Note that this class already uses a buffer for faster detection of the newline. Don't use LineReader with a BufferedStream, it's nonsense and it will throw a warning on the desktop.
Modifier and Type | Field and Description |
---|---|
boolean |
doTrim
Set to true to apply a trim in the string that is returned.
|
protected Stream |
f |
int |
maxTries
The number of times it tries to read more data if none is available.
|
protected int |
ofs |
protected ByteArrayStream |
readBuf |
boolean |
returnEmptyLines
Set to true to receive empty lines (\r\n\r\n returns "","").
|
Constructor and Description |
---|
LineReader(Stream f)
Constructs a new LineReader and sets maxTries accordingly to the type of
class: 10 if its a Socket or a PortConnector, 0 otherwise.
|
LineReader(Stream f,
byte[] buffer,
int start,
int len)
Constructs a new LineReader and sets maxTries accordingly to the type of
class: 10 if its a Socket or a PortConnector; 0, otherwise.
|
Modifier and Type | Method and Description |
---|---|
Stream |
getStream()
Returns the Stream attached to this LineReader.
|
java.lang.String |
readLine()
Returns the next line available on this stream or null if none.
|
protected boolean |
readMore()
Read more bytes from the stream.
|
protected void |
reuse()
Move the buffer to the beginning, in order to preserve the bytes that were
not read yet.
|
void |
setStream(Stream f)
Change the initial Stream to the attached one, and fetches some data.
|
protected Stream f
protected ByteArrayStream readBuf
protected int ofs
public int maxTries
public boolean doTrim
public boolean returnEmptyLines
public LineReader(Stream f) throws IOException
IOException
public LineReader(Stream f, byte[] buffer, int start, int len) throws IOException
IOException
public void setStream(Stream f) throws IOException
IOException
public Stream getStream()
protected void reuse()
protected boolean readMore() throws IOException
maxTries
times.IOException
public java.lang.String readLine() throws IOException
IOException