|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.koushikdutta.async.http.libcore.StrictLineReader
public class StrictLineReader
Buffers input from an InputStream for reading lines.
This class is used for buffered reading of lines. For purposes of this class, a line ends with
"\n" or "\r\n". End of input is reported by throwing EOFException. Unterminated line at
end of input is invalid and will be ignored, the caller may use hasUnterminatedLine()
to detect it after catching the EOFException.
This class is intended for reading input that strictly consists of lines, such as line-based
cache entries or cache journal. Unlike the BufferedReader which in conjunction with
InputStreamReader provides similar functionality, this class uses different
end-of-input reporting and a more restrictive definition of a line.
This class supports only charsets that encode '\r' and '\n' as a single byte with value 13
and 10, respectively, and the representation of no other character contains these values.
We currently check in constructor that the charset is one of US-ASCII, UTF-8 and ISO-8859-1.
The default charset is US_ASCII.
| Constructor Summary | |
|---|---|
StrictLineReader(java.io.InputStream in)
Constructs a new StrictLineReader with the default capacity and charset. |
|
StrictLineReader(java.io.InputStream in,
java.nio.charset.Charset charset)
Constructs a new LineReader with the specified charset and the default capacity. |
|
StrictLineReader(java.io.InputStream in,
int capacity)
Constructs a new LineReader with the specified capacity and the default charset. |
|
StrictLineReader(java.io.InputStream in,
int capacity,
java.nio.charset.Charset charset)
Constructs a new LineReader with the specified capacity and charset. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the reader by closing the underlying InputStream and
marking this reader as closed. |
boolean |
hasUnterminatedLine()
Check whether there was an unterminated line at end of input after the line reader reported end-of-input with EOFException. |
int |
readInt()
Read an int from a line containing its decimal representation. |
java.lang.String |
readLine()
Reads the next line. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public StrictLineReader(java.io.InputStream in)
StrictLineReader with the default capacity and charset.
in - the InputStream to read data from.
java.lang.NullPointerException - if in is null.
public StrictLineReader(java.io.InputStream in,
int capacity)
LineReader with the specified capacity and the default charset.
in - the InputStream to read data from.capacity - the capacity of the buffer.
java.lang.NullPointerException - if in is null.
java.lang.IllegalArgumentException - for negative or zero capacity.
public StrictLineReader(java.io.InputStream in,
java.nio.charset.Charset charset)
LineReader with the specified charset and the default capacity.
in - the InputStream to read data from.charset - the charset used to decode data.
Only US-ASCII, UTF-8 and ISO-8859-1 is supported.
java.lang.NullPointerException - if in or charset is null.
java.lang.IllegalArgumentException - if the specified charset is not supported.
public StrictLineReader(java.io.InputStream in,
int capacity,
java.nio.charset.Charset charset)
LineReader with the specified capacity and charset.
in - the InputStream to read data from.capacity - the capacity of the buffer.charset - the charset used to decode data.
Only US-ASCII, UTF-8 and ISO-8859-1 is supported.
java.lang.NullPointerException - if in or charset is null.
java.lang.IllegalArgumentException - if capacity is negative or zero
or the specified charset is not supported.| Method Detail |
|---|
public void close()
throws java.io.IOException
InputStream and
marking this reader as closed.
close in interface java.io.Closeablejava.io.IOException - for errors when closing the underlying InputStream.
public java.lang.String readLine()
throws java.io.IOException
"\n" or "\r\n",
this end of line marker is not included in the result.
java.io.IOException - for underlying InputStream errors.
java.io.EOFException - for the end of source stream.
public int readInt()
throws java.io.IOException
int from a line containing its decimal representation.
int from the next line.
java.io.IOException - for underlying InputStream errors or conversion error.
java.io.EOFException - for the end of source stream.public boolean hasUnterminatedLine()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||