public class ByteCountingPushBackInputStream extends java.io.PushbackInputStream
PushBackInputStream that also keeps track of the number
of consumed bytes at any given time.| Modifier and Type | Field and Description |
|---|---|
protected long |
consumed
Offset relative to beginning of stream.
|
protected long |
counter
Byte counter which can also be changed.
|
protected int |
pushback_size
Pushback buffer size.
|
static int |
READLINE_INITIAL_SIZE
Read line initial size.
|
| Constructor and Description |
|---|
ByteCountingPushBackInputStream(java.io.InputStream in,
int size)
Given an
InputStream and a push back buffer size returns
a wrapped input stream with push back capabilities. |
| Modifier and Type | Method and Description |
|---|---|
long |
getConsumed()
Retrieve the number of bytes consumed by this stream.
|
long |
getCounter()
Retrieve the current counter value.
|
int |
getPushbackSize()
Get the pushback buffer size.
|
void |
mark(int readlimit) |
boolean |
markSupported() |
int |
peek(byte[] buffer)
Peek into the stream by filling as much of the supplied array as
possible before unreading the stream and returning.
|
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b,
int off,
int len) |
int |
readFully(byte[] buffer)
Guaranteed to read the exact number of bytes that are in the array,
if not, the bytes are pushed back into the stream before returning.
|
java.lang.String |
readLine()
Read a single line into a string.
|
void |
reset() |
void |
setCounter(long bytes)
Change the counter value.
|
long |
skip(long n) |
void |
unread(byte[] b) |
void |
unread(byte[] b,
int off,
int len) |
void |
unread(int b) |
public static final int READLINE_INITIAL_SIZE
protected int pushback_size
protected long consumed
protected long counter
public ByteCountingPushBackInputStream(java.io.InputStream in, int size)
InputStream and a push back buffer size returns
a wrapped input stream with push back capabilities.in - InputStream to wrapsize - push back buffer sizepublic int getPushbackSize()
public long getConsumed()
public void setCounter(long bytes)
bytes - new counter valuepublic long getCounter()
public boolean markSupported()
markSupported in class java.io.PushbackInputStreampublic void mark(int readlimit)
mark in class java.io.PushbackInputStreampublic void reset() throws java.io.IOException
reset in class java.io.PushbackInputStreamjava.io.IOExceptionpublic int read() throws java.io.IOException
read in class java.io.PushbackInputStreamjava.io.IOExceptionpublic int read(byte[] b) throws java.io.IOException
read in class java.io.FilterInputStreamjava.io.IOExceptionpublic int read(byte[] b, int off, int len) throws java.io.IOException
read in class java.io.PushbackInputStreamjava.io.IOExceptionpublic long skip(long n) throws java.io.IOException
skip in class java.io.PushbackInputStreamjava.io.IOExceptionpublic void unread(int b) throws java.io.IOException
unread in class java.io.PushbackInputStreamjava.io.IOExceptionpublic void unread(byte[] b) throws java.io.IOException
unread in class java.io.PushbackInputStreamjava.io.IOExceptionpublic void unread(byte[] b, int off, int len) throws java.io.IOException
unread in class java.io.PushbackInputStreamjava.io.IOExceptionpublic java.lang.String readLine() throws java.io.IOException
java.io.IOException - if an I/O error occurs while reading linepublic int readFully(byte[] buffer) throws java.io.IOException
buffer - byte buffer to read bytes intojava.io.IOException - if an I/O error occurs while reading arraypublic int peek(byte[] buffer) throws java.io.IOException
buffer - byte buffer to read bytes intojava.io.IOException - if an I/O error occurs while reading arrayCopyright © 2011–2023. All rights reserved.