- java.lang.Object
-
- java.io.InputStream
-
- org.hsqldb.lib.CountdownInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public final class CountdownInputStream extends java.io.InputStream
Counts down from a specified value the number of bytes actually read from the wrapped InputStream.Returns minus one (-1) early from readXXX methods if the count down reaches zero (0) before the end of the wrapped InputStream is encountered.
This class is especially useful when a fixed number of bytes is to be read from an InputStream that is in turn to be used as the source for an
InputStreamReader
.- Since:
- 1.9.0
- Author:
- Campbell Burnet (campbell-burnet@users dot sourceforge.net)
-
-
Constructor Summary
Constructors Constructor Description CountdownInputStream(java.io.InputStream is)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
long
getCount()
int
read()
int
read(byte[] buf)
int
read(byte[] buf, int off, int len)
void
setCount(long count)
long
skip(long count)
-
-
-
Method Detail
-
read
public int read() throws java.io.IOException
- Specified by:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] buf) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] buf, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.InputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.InputStream
- Throws:
java.io.IOException
-
skip
public long skip(long count) throws java.io.IOException
- Overrides:
skip
in classjava.io.InputStream
- Throws:
java.io.IOException
-
getCount
public long getCount()
-
setCount
public void setCount(long count)
-
-