Class BufferedInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
- Direct Known Subclasses:
TarInputStream
-
Constructor Summary
ConstructorsConstructorDescriptionCreates aBufferedInputStreamand saves its argument, the input streamin, for later use.BufferedInputStream(InputStream in, int size) Creates aBufferedInputStreamwith the specified buffer size, and saves its argument, the input streamin, for later use.BufferedInputStream(InputStream in, int size, String name) Creates aBufferedInputStreamwith the specified buffer size, and saves its argument, the input streamin, for later use.BufferedInputStream(InputStream in, String name) Creates aBufferedInputStreamand saves its argument, the input streamin, for later use. -
Method Summary
Modifier and TypeMethodDescriptionintReturns 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.voidclose()Closes this input stream and releases any system resources associated with the stream.If applicable this member represents the connection object for the streamstatic intThe default size for a stream bufferAllows access to the underlying input stream if desiredlongReturns the time of the last activitygetName()Indicates the name of the stream for debugging purposesintReturns the total number of bytes read from this stream so farintgetYield()Allows setting a yield duration for this stream which is useful for background operations to release CPUbooleanReturns
booleanPrints out all the data that passes through this stream to the console.voidmark(int readlimit) See the general contract of themarkmethod ofInputStream.booleanTests if this input stream supports themarkandresetmethods.intread()See the general contract of thereadmethod ofInputStream.intread(byte[] b) intread(byte[] b, int off, int len) Reads bytes from this byte-input stream into the specified byte array, starting at the given offset.voidreset()See the general contract of theresetmethod ofInputStream.voidsetConnection(Object connection) If applicable this member represents the connection object for the streamstatic voidsetDefaultBufferSize(int aDefaultBufferSize) The default size for a stream buffervoidsetDisableBuffering(boolean disableBuffering) Parameters
voidsetPrintInput(boolean printInput) Prints out all the data that passes through this stream to the console.voidsetProgressListener(IOProgressListener progressListener) Sets the callback for IO updates from a buffered streamvoidsetYield(int yield) Allows setting a yield duration for this stream which is useful for background operations to release CPUlongskip(long n) See the general contract of theskipmethod ofInputStream.voidstop()Stop reading from the stream, invoking this will cause the read() to return -1
-
Constructor Details
-
BufferedInputStream
Creates a
BufferedInputStreamand saves its argument, the input streamin, for later use. An internal buffer array is created and stored inbuf.Parameters
in: the underlying input stream.
-
BufferedInputStream
Creates a
BufferedInputStreamand saves its argument, the input streamin, for later use. An internal buffer array is created and stored inbuf.Parameters
-
in: the underlying input stream. -
name: the name of the stream
-
-
BufferedInputStream
Creates a
BufferedInputStreamwith the specified buffer size, and saves its argument, the input streamin, for later use. An internal buffer array of lengthsizeis created and stored inbuf.Parameters
-
in: the underlying input stream. -
size: the buffer size.
Throws
IllegalArgumentException: if size <= 0.
-
-
BufferedInputStream
Creates a
BufferedInputStreamwith the specified buffer size, and saves its argument, the input streamin, for later use. An internal buffer array of lengthsizeis created and stored inbuf.Parameters
-
in: the underlying input stream. -
size: the buffer size. -
name: the name of the stream
Throws
IllegalArgumentException: if size <= 0.
-
-
-
Method Details
-
getDefaultBufferSize
public static int getDefaultBufferSize()The default size for a stream buffer
Returns
the defaultBufferSize
-
setDefaultBufferSize
public static void setDefaultBufferSize(int aDefaultBufferSize) The default size for a stream buffer
Parameters
aDefaultBufferSize: the defaultBufferSize to set
-
getName
Indicates the name of the stream for debugging purposes
Returns
the name of the stream
-
getInternal
Allows access to the underlying input stream if desired
Returns
the internal input stream
-
read
See the general contract of the
readmethod ofInputStream.Returns
- Specified by:
readin classInputStream- Returns:
the next byte of data, or
-1if the end of the stream is reached.Throws
IOException: @throws IOException if this input stream has been closed by invoking its#close()method, or an I/O error occurs.
- Throws:
IOException
-
read
Reads 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) readmethod of theInputStreamclass. As an additional convenience, it attempts to read as many bytes as possible by repeatedly invoking thereadmethod of the underlying stream. This iteratedreadcontinues 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, or -
The
availablemethod of the underlying stream returns zero, indicating that further input requests would block.
If the first
readon the underlying stream returns-1to 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
-
b: destination buffer. -
off: offset at which to start storing bytes. -
len: maximum number of bytes to read.
Returns
- Overrides:
readin classInputStream- Returns:
the number of bytes read, or
-1if the end of the stream has been reached.Throws
IOException: @throws IOException if this input stream has been closed by invoking its#close()method, or an I/O error occurs.
- Throws:
IOException
-
-
skip
See the general contract of the
skipmethod ofInputStream.Throws
IOException: @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.
- Overrides:
skipin classInputStream- Throws:
IOException
-
available
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. 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 thein.available().Returns
- Overrides:
availablein classInputStream- Returns:
an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.
Throws
IOException: @throws IOException if this input stream has been closed by invoking its close() method, or an I/O error occurs.
- Throws:
IOException
-
mark
public void mark(int readlimit) See the general contract of the
markmethod ofInputStream.Parameters
readlimit: @param readlimit the maximum limit of bytes that can be read before the mark position becomes invalid.
- Overrides:
markin classInputStream
-
reset
See the general contract of the
resetmethod ofInputStream.If
markposis-1(no mark has been set or the mark has been invalidated), anIOExceptionis thrown. Otherwise,posis set equal tomarkpos.Throws
IOException: @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.
- Overrides:
resetin classInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()Tests if this input stream supports the
markandresetmethods. ThemarkSupportedmethod ofBufferedInputStreamreturnstrue.Returns
- Overrides:
markSupportedin classInputStream- Returns:
a
booleanindicating if this stream type supports themarkandresetmethods.See also
-
java.io.InputStream#mark(int)
-
java.io.InputStream#reset()
-
-
close
Closes this input stream and releases any system resources associated with the stream. Once the stream has been closed, further read(), available(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.
Throws
IOException: if an I/O error occurs.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
getLastActivityTime
public long getLastActivityTime()Returns the time of the last activity
Returns
time of the last activity on this stream
-
getTotalBytesRead
public int getTotalBytesRead()Returns the total number of bytes read from this stream so far
Returns
the total number of bytes read from this stream so far
-
setProgressListener
Sets the callback for IO updates from a buffered stream
Parameters
progressListener: the progressListener to set
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
getConnection
If applicable this member represents the connection object for the stream
Returns
the connection
-
setConnection
If applicable this member represents the connection object for the stream
Parameters
connection: the connection to set
-
isDisableBuffering
public boolean isDisableBuffering()Returns
the disableBuffering
-
setDisableBuffering
public void setDisableBuffering(boolean disableBuffering) Parameters
disableBuffering: the disableBuffering to set
-
isPrintInput
public boolean isPrintInput()Prints out all the data that passes through this stream to the console. This is a very useful debugging tool.
Returns
the printInput
-
setPrintInput
public void setPrintInput(boolean printInput) Prints out all the data that passes through this stream to the console. This is a very useful debugging tool.
Parameters
printInput: the printInput to set
-
getYield
public int getYield()Allows setting a yield duration for this stream which is useful for background operations to release CPU
Returns
the yield
-
setYield
public void setYield(int yield) Allows setting a yield duration for this stream which is useful for background operations to release CPU
Parameters
yield: the yield to set
-
stop
public void stop()Stop reading from the stream, invoking this will cause the read() to return -1
-