Applications that need to define a subclass of InputStream
must always provide a method that returns the next byte of input.
java.io.BufferedInputStream
, java.io.ByteArrayInputStream
, java.io.DataInputStream
, java.io.FilterInputStream
, java.io.InputStream#read()
, java.io.OutputStream
, java.io.PushbackInputStream
Modifier and Type | Field and Description |
---|---|
private static final int | |
private static final int | MAX_BUFFER_SIZE
The maximum size of array to allocate. |
private static final int |
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public int | Returns: an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or0 when it reaches the end of the input stream.Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. |
public void | close()
Implements java. Closes this input stream and releases any system resources associated with the stream. |
public void | mark(int
the maximum limit of bytes that can be read before
the mark position becomes invalid. readlimit)Marks the current position in this input stream. |
public boolean | Returns: true if this stream instance supports the mark
and reset methods; false otherwise.Tests if this input stream supports the |
public static InputStream | Returns: anInputStream which contains no bytesReturns a new |
public abstract int | Returns: the next byte of data, or-1 if the end of the
stream is reached.Reads the next byte of data from the input stream. |
public int | Returns: the total number of bytes read into the buffer, or-1 if there is no more data because the end of
the stream has been reached.the buffer into which the data is read. b)Reads some number of bytes from the input stream and stores them into
the buffer array |
public int | Returns: the total number of bytes read into the buffer, or-1 if there is no more data because the end of
the stream has been reached.the buffer into which the data is read. b, int the start offset in array off, int b
at which the data is written.the maximum number of bytes to read. len)Reads up to |
public byte[] | Returns: a byte array containing the bytes read from this input streamReads all remaining bytes from the input stream. |
public byte[] | Returns: a byte array containing the bytes read from this input streamthe maximum number of bytes to read len)Reads up to a specified number of bytes from the input stream. |
public int | Returns: the actual number of bytes read into the bufferthe byte array into which the data is read b, int the start offset in off, int b at which the data is writtenthe maximum number of bytes to read len)Reads the requested number of bytes from the input stream into the given byte array. |
public void | reset()
Repositions this stream to the position at the time the
|
public long | Returns: the actual number of bytes skipped which might be zero.the number of bytes to be skipped. n)Skips over and discards |
public void | skipNBytes(long
the number of bytes to be skipped. n)Skips over and discards exactly |
public long | Returns: the number of bytes transferredthe output stream, non-null out)Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read. |
DEFAULT_BUFFER_SIZE | back to summary |
---|---|
private static final int DEFAULT_BUFFER_SIZE |
MAX_BUFFER_SIZE | back to summary |
---|---|
private static final int MAX_BUFFER_SIZE The maximum size of array to allocate. Some VMs reserve some header words in an array. Attempts to allocate larger arrays may result in OutOfMemoryError: Requested array size exceeds VM limit |
MAX_SKIP_BUFFER_SIZE | back to summary |
---|---|
private static final int MAX_SKIP_BUFFER_SIZE |
InputStream | back to summary |
---|---|
public InputStream() Constructor for subclasses to call. |
available | back to summary |
---|---|
public 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, which may be 0, or 0 when end of stream is detected. The read might be on 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. Note that while some implementations of A subclass's implementation of this method may choose to throw an
Implementation Specification The API Note This method should be overridden by subclasses.
|
close | back to summary |
---|---|
public void close() throws IOException Implements java. Closes this input stream and releases any system resources associated with the stream. Implementation Specification The
|
mark | back to summary |
---|---|
public void mark(int readlimit) Marks the current position in this input stream. A subsequent call to
the The The general contract of Marking a closed stream should not have any effect on the stream. Implementation Specification The
|
markSupported | back to summary |
---|---|
public boolean markSupported() Tests if this input stream supports the Implementation Specification The
|
nullInputStream | back to summary |
---|---|
public static InputStream nullInputStream() Returns a new While the stream is open, the The
|
read | back to summary |
---|---|
public abstract int read() throws IOException Reads the next byte of data from the input stream. The value byte is
returned as an
|
read | back to summary |
---|---|
public int read(byte[] b) throws IOException Reads some number of bytes from the input stream and stores them into
the buffer array If the length of The first byte read is stored into element Implementation Specification The read(b, 0, b.length)
|
read | back to summary |
---|---|
public int read(byte[] b, int off, int len) throws IOException Reads up to This method blocks until input data is available, end of file is detected, or an exception is thrown. If The first byte read is stored into element In every case, elements Implementation Specification The
|
readAllBytes | back to summary |
---|---|
public byte[] readAllBytes() throws IOException Reads all remaining bytes from the input stream. This method blocks until all remaining bytes have been read and end of stream is detected, or an exception is thrown. This method does not close the input stream. When this stream reaches end of stream, further invocations of this method will return an empty byte array. Note that this method is intended for simple cases where it is convenient to read all bytes into a byte array. It is not intended for reading input streams with large amounts of data. The behavior for the case where the input stream is asynchronously closed, or the thread interrupted during the read, is highly input stream specific, and therefore not specified. If an I/O error occurs reading from the input stream, then it may do so after some, but not all, bytes have been read. Consequently the input stream may not be at end of stream and may be in an inconsistent state. It is strongly recommended that the stream be promptly closed if an I/O error occurs. Implementation Specification This method invokes
|
readNBytes | back to summary |
---|---|
public byte[] readNBytes(int len) throws IOException Reads up to a specified number of bytes from the input stream. This method blocks until the requested number of bytes has been read, end of stream is detected, or an exception is thrown. This method does not close the input stream. The length of the returned array equals the number of bytes read
from the stream. If When this stream reaches end of stream, further invocations of this method will return an empty byte array. Note that this method is intended for simple cases where it is
convenient to read the specified number of bytes into a byte array. The
total amount of memory allocated by this method is proportional to the
number of bytes read from the stream which is bounded by The behavior for the case where the input stream is asynchronously closed, or the thread interrupted during the read, is highly input stream specific, and therefore not specified. If an I/O error occurs reading from the input stream, then it may do so after some, but not all, bytes have been read. Consequently the input stream may not be at end of stream and may be in an inconsistent state. It is strongly recommended that the stream be promptly closed if an I/O error occurs. Implementation Note The number of bytes allocated to read data from this stream and return
the result is bounded by
|
readNBytes | back to summary |
---|---|
public int readNBytes(byte[] b, int off, int len) throws IOException Reads the requested number of bytes from the input stream into the given
byte array. This method blocks until In the case where end of stream is reached before If The first byte read is stored into element The behavior for the case where the input stream is asynchronously closed, or the thread interrupted during the read, is highly input stream specific, and therefore not specified. If an I/O error occurs reading from the input stream, then it may do
so after some, but not all, bytes of
|
reset | back to summary |
---|---|
public void reset() throws IOException Repositions this stream to the position at the time the
The general contract of
Implementation Specification The method
|
skip | back to summary |
---|---|
public long skip(long n) throws IOException Skips over and discards Implementation Specification The
|
skipNBytes | back to summary |
---|---|
public void skipNBytes(long n) throws IOException Skips over and discards exactly This method blocks until the requested number of bytes has been skipped, end of file is reached, or an exception is thrown. If end of stream is reached before the stream is at the desired
position, then an If an I/O error occurs, then the input stream may be in an inconsistent state. It is strongly recommended that the stream be promptly closed if an I/O error occurs. Implementation Note Subclasses are encouraged to provide a more efficient implementation of this method. Implementation Specification If
|
transferTo | back to summary |
---|---|
public long transferTo(OutputStream out) throws IOException Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read. On return, this input stream will be at end of stream. This method does not close either stream. This method may block indefinitely reading from the input stream, or writing to the output stream. The behavior for the case where the input and/or output stream is asynchronously closed, or the thread interrupted during the transfer, is highly input and output stream specific, and therefore not specified.
If the total number of bytes transferred is greater than Long#MAX_VALUE, then If an I/O error occurs reading from the input stream or writing to the output stream, then it may do so after some bytes have been read or written. Consequently the input stream may not be at end of stream and one, or both, streams may be in an inconsistent state. It is strongly recommended that both streams be promptly closed if an I/O error occurs.
|