public class ProcFileReader extends Object implements Closeable
/proc/
files quickly. Walks
through the stream using a single space ' '
as token separator, and
requires each line boundary to be explicitly acknowledged using
finishLine()
. Assumes StandardCharsets.US_ASCII
encoding.
Currently doesn't support formats based on \0
, tabs, or repeated
delimiters.
Constructor and Description |
---|
ProcFileReader(InputStream stream) |
ProcFileReader(InputStream stream,
int bufferSize) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this stream and releases any system resources associated
with it.
|
void |
finishLine()
Finish current line, skipping any remaining data.
|
boolean |
hasMoreData()
Check if stream has more data to be parsed.
|
int |
nextInt()
Parse and return next token as base-10 encoded
int . |
long |
nextLong()
Parse and return next token as base-10 encoded
long . |
long |
nextOptionalLong(long def)
Parse and return next token as base-10 encoded
long , or return
the given default value if no remaining tokens on current line. |
String |
nextString()
Parse and return next token as
String . |
public ProcFileReader(InputStream stream) throws IOException
IOException
public ProcFileReader(InputStream stream, int bufferSize) throws IOException
IOException
public boolean hasMoreData()
public void finishLine() throws IOException
IOException
public String nextString() throws IOException
String
.IOException
public long nextLong() throws IOException
long
.IOException
public long nextOptionalLong(long def) throws IOException
long
, or return
the given default value if no remaining tokens on current line.IOException
public int nextInt() throws IOException
int
.IOException
public void close() throws IOException
Closeable
close
in interface Closeable
close
in interface AutoCloseable
IOException
- if an I/O error occurs