Package org.apache.commons.io.input
Class UnsynchronizedFilterInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.io.input.UnsynchronizedFilterInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
UnsynchronizedBufferedInputStream
public class UnsynchronizedFilterInputStream extends java.io.InputStream
An unsynchronized version ofFilterInputStream
, 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.
- Since:
- 2.12.0
- See Also:
FilterInputStream
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UnsynchronizedFilterInputStream.Builder
Builds a newUnsynchronizedFilterInputStream
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
Returns the number of bytes that are available before this stream will block.static UnsynchronizedFilterInputStream.Builder
builder()
Constructs a newUnsynchronizedFilterInputStream.Builder
.void
close()
Closes this stream.void
mark(int readlimit)
Sets a mark position in this stream.boolean
markSupported()
Indicates whether this stream supportsmark()
andreset()
.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 arraybuffer
.int
read(byte[] buffer, int offset, int count)
Reads at mostcount
bytes from this stream and stores them in the byte arraybuffer
starting atoffset
.void
reset()
Resets this stream to the last marked location.long
skip(long count)
Skipscount
number of bytes in this stream.
-
-
-
Method Detail
-
builder
public static UnsynchronizedFilterInputStream.Builder builder()
Constructs a newUnsynchronizedFilterInputStream.Builder
.- Returns:
- a new
UnsynchronizedFilterInputStream.Builder
.
-
available
public int available() throws java.io.IOException
Returns the number of bytes that are available before this stream will block.- Overrides:
available
in classjava.io.InputStream
- Returns:
- the number of bytes available before blocking.
- Throws:
java.io.IOException
- if an error occurs in this stream.
-
close
public void close() throws java.io.IOException
Closes this stream. This implementation closes the filtered stream.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
- if an error occurs while closing this stream.
-
mark
public void mark(int readlimit)
Sets a mark position in this stream. The parameterreadlimit
indicates how many bytes can be read before the mark is invalidated. Sendingreset()
will reposition this stream back to the marked position, provided thatreadlimit
has not been surpassed.This implementation sets a mark in the filtered stream.
- Overrides:
mark
in classjava.io.InputStream
- Parameters:
readlimit
- the number of bytes that can be read from this stream before the mark is invalidated.- See Also:
markSupported()
,reset()
-
markSupported
public boolean markSupported()
Indicates whether this stream supportsmark()
andreset()
. This implementation returns whether or not the filtered stream supports marking.- Overrides:
markSupported
in classjava.io.InputStream
- Returns:
true
ifmark()
andreset()
are supported,false
otherwise.- See Also:
mark(int)
,reset()
,skip(long)
-
read
public int read() throws java.io.IOException
Reads a single byte from the filtered stream and returns it as an integer in the range from 0 to 255. Returns -1 if the end of this stream has been reached.- Specified by:
read
in classjava.io.InputStream
- Returns:
- the byte read or -1 if the end of the filtered stream has been reached.
- Throws:
java.io.IOException
- if the stream is closed or another IOException occurs.
-
read
public int read(byte[] buffer) throws java.io.IOException
Reads bytes from this stream and stores them in the byte arraybuffer
. 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.- Overrides:
read
in classjava.io.InputStream
- Parameters:
buffer
- the byte array in which to store the read bytes.- Returns:
- the number of bytes actually read or -1 if the end of the filtered stream has been reached while reading.
- Throws:
java.io.IOException
- if this stream is closed or another IOException occurs.
-
read
public int read(byte[] buffer, int offset, int count) throws java.io.IOException
Reads at mostcount
bytes from this stream and stores them in the byte arraybuffer
starting atoffset
. 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.- Overrides:
read
in classjava.io.InputStream
- Parameters:
buffer
- the byte array in which to store the bytes read.offset
- the initial position inbuffer
to store the bytes read from this stream.count
- the maximum number of bytes to store inbuffer
.- Returns:
- the number of bytes actually read or -1 if the end of the filtered stream has been reached while reading.
- Throws:
java.io.IOException
- if this stream is closed or another I/O error occurs.
-
reset
public void reset() throws java.io.IOException
Resets this stream to the last marked location. This implementation resets the target stream.- Overrides:
reset
in classjava.io.InputStream
- Throws:
java.io.IOException
- if this stream is already closed, no mark has been set or the mark is no longer valid because more thanreadlimit
bytes have been read since setting the mark.- See Also:
mark(int)
,markSupported()
-
skip
public long skip(long count) throws java.io.IOException
Skipscount
number of bytes in this stream. Subsequentread()
's will not return these bytes unlessreset()
is used. This implementation skipscount
number of bytes in the filtered stream.
-
-