public class UnsynchronizedFilterInputStream
extends java.io.InputStream
FilterInputStream
, not thread-safe.
Wraps an existing InputStream
and performs some transformation on the input data while it is being read. Transformations can be anything from a
simple byte-wise filtering input data to an on-the-fly compression or decompression of the underlying stream. Input streams that wrap another input stream
and provide some additional functionality on top of it usually inherit from this class.
To build an instance, see UnsynchronizedFilterInputStream.Builder
.
Provenance: Apache Harmony and modified.
FilterInputStream
Modifier and Type | Class and Description |
---|---|
static class |
UnsynchronizedFilterInputStream.Builder
Builds a new
UnsynchronizedFilterInputStream instance. |
Modifier and Type | Field and Description |
---|---|
protected java.io.InputStream |
inputStream
The source input stream that is filtered.
|
Constructor and Description |
---|
UnsynchronizedFilterInputStream(java.io.InputStream inputStream)
Constructs a new
FilterInputStream with the specified input stream as source. |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of bytes that are available before this stream will block.
|
static UnsynchronizedFilterInputStream.Builder |
builder()
Constructs a new
UnsynchronizedFilterInputStream.Builder . |
void |
close()
Closes this stream.
|
void |
mark(int readLimit)
Sets a mark position in this stream.
|
boolean |
markSupported()
Indicates whether this stream supports
mark() and reset() . |
int |
read()
Reads a single byte from the filtered stream and returns it as an integer in the range from 0 to 255.
|
int |
read(byte[] buffer)
Reads bytes from this stream and stores them in the byte array
buffer . |
int |
read(byte[] buffer,
int offset,
int count)
Reads at most
count bytes from this stream and stores them in the byte array buffer starting at offset . |
void |
reset()
Resets this stream to the last marked location.
|
long |
skip(long count)
Skips
count number of bytes in this stream. |
protected volatile java.io.InputStream inputStream
UnsynchronizedFilterInputStream(java.io.InputStream inputStream)
FilterInputStream
with the specified input stream as source.inputStream
- the non-null InputStream to filter reads on.public static UnsynchronizedFilterInputStream.Builder builder()
UnsynchronizedFilterInputStream.Builder
.UnsynchronizedFilterInputStream.Builder
.public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
- if an error occurs in this stream.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
- if an error occurs while closing this stream.public void mark(int readLimit)
readLimit
indicates how many bytes can be read before the mark is invalidated. Sending
reset()
will reposition this stream back to the marked position, provided that readLimit
has not been surpassed.
This implementation sets a mark in the filtered stream.
mark
in class java.io.InputStream
readLimit
- the number of bytes that can be read from this stream before the mark is invalidated.markSupported()
,
reset()
public boolean markSupported()
mark()
and reset()
. This implementation returns whether or not the filtered stream supports
marking.markSupported
in class java.io.InputStream
true
if mark()
and reset()
are supported, false
otherwise.mark(int)
,
reset()
,
skip(long)
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
- if the stream is closed or another IOException occurs.public int read(byte[] buffer) throws java.io.IOException
buffer
. Returns the number of bytes actually read or -1 if no bytes were read and
the end of this stream was encountered. This implementation reads bytes from the filtered stream.read
in class java.io.InputStream
buffer
- the byte array in which to store the read bytes.java.io.IOException
- if this stream is closed or another IOException occurs.public int read(byte[] buffer, int offset, int count) throws java.io.IOException
count
bytes from this stream and stores them in the byte array buffer
starting at offset
. Returns the number of
bytes actually read or -1 if no bytes have been read and the end of this stream has been reached. This implementation reads bytes from the filtered
stream.read
in class java.io.InputStream
buffer
- the byte array in which to store the bytes read.offset
- the initial position in buffer
to store the bytes read from this stream.count
- the maximum number of bytes to store in buffer
.java.io.IOException
- if this stream is closed or another I/O error occurs.public void reset() throws java.io.IOException
reset
in class java.io.InputStream
java.io.IOException
- if this stream is already closed, no mark has been set or the mark is no longer valid because more than readLimit
bytes have
been read since setting the mark.mark(int)
,
markSupported()
public long skip(long count) throws java.io.IOException
count
number of bytes in this stream. Subsequent read()
's will not return these bytes unless reset()
is used. This
implementation skips count
number of bytes in the filtered stream.