public class BufferedInputStream
- Object
- InputStream
- BufferedInputStream
ImplementsAutoCloseable
Known subtypesTarInputStream
Constructors
public BufferedInputStream(InputStream in) | Creates a BufferedInputStream and saves its argument, the input stream in, for later use. |
public BufferedInputStream(InputStream in, String name) | Creates a BufferedInputStream and saves its argument, the input stream in, for later use. |
public BufferedInputStream(InputStream in, int size) | Creates a BufferedInputStream with the specified buffer size, and saves its argument, the input stream in, for later use. |
public BufferedInputStream(InputStream in, int size, String name) | Creates a BufferedInputStream with the specified buffer size, and saves its argument, the input stream in, for later use. |
Methods
public static int getDefaultBufferSize() | The default size for a stream buffer |
public static void setDefaultBufferSize(int aDefaultBufferSize) | The default size for a stream buffer |
public String getName() | Indicates the name of the stream for debugging purposes |
public InputStream getInternal() | Allows access to the underlying input stream if desired |
public synchronized int read()
throws IOException | See the general contract of the read method of InputStream. |
public synchronized int read(byte[] b, int off, int len)
throws IOException | Reads bytes from this byte-input stream into the specified byte array, starting at the given offset. |
public synchronized long skip(long n)
throws IOException | See the general contract of the skip method of InputStream. |
public synchronized int available()
throws IOException | Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. |
public synchronized void mark(int readlimit) | See the general contract of the mark method of InputStream. |
public synchronized void reset()
throws IOException | See the general contract of the reset method of InputStream. |
public boolean markSupported() | Tests if this input stream supports the mark and reset methods. |
public void close()
throws IOException | Closes this input stream and releases any system resources associated with the stream. |
public synchronized long getLastActivityTime() | Returns the time of the last activity |
public synchronized int getTotalBytesRead() | Returns the total number of bytes read from this stream so far |
public void setProgressListener(IOProgressListener progressListener) | Sets the callback for IO updates from a buffered stream |
public int read(byte[] b)
throws IOException | Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. |
public Object getConnection() | If applicable this member represents the connection object for the stream |
public void setConnection(Object connection) | If applicable this member represents the connection object for the stream |
public synchronized boolean isDisableBuffering() | |
public synchronized void setDisableBuffering(boolean disableBuffering) | |
public synchronized boolean isPrintInput() | Prints out all the data that passes through this stream to the console. |
public synchronized void setPrintInput(boolean printInput) | Prints out all the data that passes through this stream to the console. |
public synchronized int getYield() | Allows setting a yield duration for this stream which is useful for background operations to release CPU |
public synchronized void setYield(int yield) | Allows setting a yield duration for this stream which is useful for background operations to release CPU |
public synchronized void stop() | Stop reading from the stream, invoking this will cause the read() to return -1 |
Inherited methods
Constructor details
BufferedInputStream
public BufferedInputStream(InputStream in)BufferedInputStream
and saves its argument, the input stream
in, for later use. An internal
buffer array is created and stored in buf.Parameters
inInputStream- the underlying input stream.
BufferedInputStream
public BufferedInputStream(InputStream in, String name)BufferedInputStream
and saves its argument, the input stream
in, for later use. An internal
buffer array is created and stored in buf.Parameters
inInputStream- the underlying input stream.
nameString- the name of the stream
BufferedInputStream
public BufferedInputStream(InputStream in, int size)BufferedInputStream
with the specified buffer size,
and saves its argument, the input stream
in, for later use. An internal
buffer array of length size
is created and stored in buf.Parameters
inInputStream- the underlying input stream.
sizeint- the buffer size.
Throws
IllegalArgumentException- if size <= 0.
BufferedInputStream
public BufferedInputStream(InputStream in, int size, String name)BufferedInputStream
with the specified buffer size,
and saves its argument, the input stream
in, for later use. An internal
buffer array of length size
is created and stored in buf.Parameters
inInputStream- the underlying input stream.
sizeint- the buffer size.
nameString- the name of the stream
Throws
IllegalArgumentException- if size <= 0.
Method details
getDefaultBufferSize
public static int getDefaultBufferSize()Returns
setDefaultBufferSize
public static void setDefaultBufferSize(int aDefaultBufferSize)Parameters
aDefaultBufferSizeint- the defaultBufferSize to set
getName
public String getName()Returns
getInternal
public InputStream getInternal()Returns
read
public synchronized int read()
throws IOExceptionread
method of InputStream.Returns
-1 if the end of the
stream is reached.Throws
IOException- if this input stream has been closed by
invoking its
#close()method, or an I/O error occurs.
read
public synchronized int read(byte[] b, int off, int len)
throws IOExceptionReads bytes from this byte-input stream into the specified byte array, starting at the given offset.
This method implements the general contract of the corresponding
int, int) read method of
the InputStream class. As an additional
convenience, it attempts to read as many bytes as possible by repeatedly
invoking the read method of the underlying stream. This
iterated read continues until one of the following
conditions becomes true:
The specified number of bytes have been read,
The
readmethod of the underlying stream returns-1, indicating end-of-file, orThe
availablemethod of the underlying stream returns zero, indicating that further input requests would block.
If the first read on the underlying stream returns
-1 to indicate end-of-file then this method returns
-1. Otherwise this method returns the number of bytes
actually read.
Subclasses of this class are encouraged, but not required, to attempt to read as many bytes as possible in the same fashion.
Parameters
bbyte[]- destination buffer.
offint- offset at which to start storing bytes.
lenint- maximum number of bytes to read.
Returns
-1 if the end of
the stream has been reached.Throws
IOException- if this input stream has been closed by
invoking its
#close()method, or an I/O error occurs.
skip
public synchronized long skip(long n)
throws IOExceptionskip
method of InputStream.Throws
IOException- if the stream does not support seek,
or if this input stream has been closed by
invoking its
#close()method, or an I/O error occurs.
available
public synchronized int available()
throws IOExceptionReturns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream. The next invocation might be the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.
This method returns the sum of the number of bytes remaining to be read in
the buffer (count - pos) and the result of calling the
in.available().
Returns
Throws
IOException- if this input stream has been closed by invoking its close() method, or an I/O error occurs.
mark
public synchronized void mark(int readlimit)mark
method of InputStream.Parameters
readlimitint- the maximum limit of bytes that can be read before the mark position becomes invalid.
reset
public synchronized void reset()
throws IOExceptionSee the general contract of the reset
method of InputStream.
If markpos is -1
(no mark has been set or the mark has been
invalidated), an IOException
is thrown. Otherwise, pos is
set equal to markpos.
Throws
IOException- if this stream has not been marked or,
if the mark has been invalidated, or the stream
has been closed by invoking its
#close()method, or an I/O error occurs.
markSupported
public boolean markSupported()mark
and reset methods. The markSupported
method of BufferedInputStream returns
true.Returns
boolean indicating if this stream type supports
the mark and reset methods.close
public void close()
throws IOExceptionThrows
IOException- if an I/O error occurs.
getLastActivityTime
public synchronized long getLastActivityTime()Returns
getTotalBytesRead
public synchronized int getTotalBytesRead()Returns
setProgressListener
public void setProgressListener(IOProgressListener progressListener)Parameters
progressListenerIOProgressListener- the progressListener to set
read
public int read(byte[] b)
throws IOExceptionk through b[b.length-1] unaffected.
If the first byte cannot be read for any reason other than end of file, then an IOException is thrown. In particular, an IOException is thrown if the input stream has been closed.
The read(b) method for class InputStream has the same effect as: read(b, 0, b.length)Throws
getConnection
public Object getConnection()Returns
setConnection
public void setConnection(Object connection)Parameters
connectionObject- the connection to set
isDisableBuffering
public synchronized boolean isDisableBuffering()Returns
setDisableBuffering
public synchronized void setDisableBuffering(boolean disableBuffering)Parameters
disableBufferingboolean- the disableBuffering to set
isPrintInput
public synchronized boolean isPrintInput()Returns
setPrintInput
public synchronized void setPrintInput(boolean printInput)Parameters
printInputboolean- the printInput to set
getYield
public synchronized int getYield()Returns
setYield
public synchronized void setYield(int yield)Parameters
yieldint- the yield to set
stop
public synchronized void stop()