Build 1.0_r1(from source)

java.io
Class InputStream

java.lang.Object
  extended by java.io.InputStream
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
AssetManager.AssetInputStream, ByteArrayInputStream, ChunkedInputStream, ContentLengthInputStream, DrmRawContent.DrmInputStream, EofSensorInputStream, FileInputStream, FilterInputStream, IdentityInputStream, LocalSocketImpl.SocketInputStream, ObjectInputStream, PipedInputStream, ReaderInputStream, SequenceInputStream, StringBufferInputStream, ZipFile.RAFStream

public abstract class InputStream
extends Object
implements Closeable

InputStream is an abstract class for all byte input streams. It provides basic method implementations for reading bytes from a stream.

See Also:
OutputStream

Constructor Summary
InputStream()
          This constructor does nothing interesting.
 
Method Summary
 int available()
          Returns a int representing then number of bytes that are available before this InputStream will block.
 void close()
          Close the InputStream.
 void mark(int readlimit)
          Set a Mark position in this InputStream.
 boolean markSupported()
          Returns a boolean indicating whether or not this InputStream supports mark() and reset().
abstract  int read()
          Reads a single byte from this InputStream and returns the result as an int.
 int read(byte[] b)
          Reads bytes from the Stream and stores them in byte array b.
 int read(byte[] b, int offset, int length)
          Reads at most length bytes from the Stream and stores them in byte array b starting at offset.
 void reset()
          Reset this InputStream to the last marked location.
 long skip(long n)
          Skips n number of bytes in this InputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputStream

public InputStream()
This constructor does nothing interesting. Provided for signature compatibility.

Method Detail

available

public int available()
              throws IOException
Returns a int representing then number of bytes that are available before this InputStream will block. This method always returns 0. Subclasses should override and indicate the correct number of bytes available.

Returns:
the number of bytes available before blocking.
Throws:
IOException - If an error occurs in this InputStream.

close

public void close()
           throws IOException
Close the InputStream. Concrete implementations of this class should free any resources during close. This implementation does nothing.

Specified by:
close in interface Closeable
Throws:
IOException - If an error occurs attempting to close this InputStream.

mark

public void mark(int readlimit)
Set a Mark position in this InputStream. The parameter readLimit indicates how many bytes can be read before a mark is invalidated. Sending reset() will reposition the Stream back to the marked position provided readLimit has not been surpassed.

This default implementation does nothing and concrete subclasses must provide their own implementations.

Parameters:
readlimit - the number of bytes to be able to read before invalidating the mark.

markSupported

public boolean markSupported()
Returns a boolean indicating whether or not this InputStream supports mark() and reset(). This class provides a default implementation which returns false.

Returns:
true if mark() and reset() are supported, false otherwise.

read

public abstract int read()
                  throws IOException
Reads a single byte from this InputStream and returns the result as an int. The low-order byte is returned or -1 of the end of stream was encountered. This abstract implementation must be provided by concrete subclasses.

Returns:
the byte read or -1 if end of stream.
Throws:
IOException - If the stream is already closed or another IOException occurs.

read

public int read(byte[] b)
         throws IOException
Reads bytes from the Stream and stores them in byte array b. Answer the number of bytes actually read or -1 if no bytes were read and end of stream was encountered.

Parameters:
b - the byte array in which to store the read bytes.
Returns:
the number of bytes actually read or -1 if end of stream.
Throws:
IOException - If the stream is already closed or another IOException occurs.

read

public int read(byte[] b,
                int offset,
                int length)
         throws IOException
Reads at most length bytes from the Stream and stores them in byte array b starting at offset. Answer the number of bytes actually read or -1 if no bytes were read and end of stream was encountered.

Parameters:
b - the byte array in which to store the read bytes.
offset - the offset in b to store the read bytes.
length - the maximum number of bytes to store in b.
Returns:
the number of bytes actually read or -1 if end of stream.
Throws:
IOException - If the stream is already closed or another IOException occurs.

reset

public void reset()
           throws IOException
Reset this InputStream to the last marked location. If the readlimit has been passed or no mark has been set, throw IOException. This implementation throws IOException and concrete subclasses should provide proper implementations.

Throws:
IOException - If the stream is already closed or another IOException occurs.

skip

public long skip(long n)
          throws IOException
Skips n number of bytes in this InputStream. Subsequent read()'s will not return these bytes unless reset() is used. This method may perform multiple reads to read n bytes. This default implementation reads n bytes into a temporary buffer. Concrete subclasses should provide their own implementation.

Parameters:
n - the number of bytes to skip.
Returns:
the number of bytes actually skipped.
Throws:
IOException - If the stream is already closed or another IOException occurs.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature