All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.io.InputStream

java.lang.Object
   |
   +----java.io.InputStream

public abstract class InputStream
extends Object
This abstract class is the superclass of all classes representing an input stream of bytes.

Applications that need to define a subclass of InputStream must always provide a method that returns the next byte of input.

See Also:
BufferedInputStream, ByteArrayInputStream, DataInputStream, FilterInputStream, read, OutputStream, PushbackInputStream

Constructor Index

 o InputStream()

Method Index

 o available()
Returns the number of bytes that can be read from this input stream without blocking.
 o close()
Closes this input stream and releases any system resources associated with the stream.
 o mark(int)
Marks the current position in this input stream.
 o markSupported()
Tests if this input stream supports the mark and reset methods.
 o read()
Reads the next byte of data from this input stream.
 o read(byte[])
Reads up to b.length bytes of data from this input stream into an array of bytes.
 o read(byte[], int, int)
Reads up to len bytes of data from this input stream into an array of bytes.
 o reset()
Repositions this stream to the position at the time the mark method was last called on this input stream.
 o skip(long)
Skips over and discards n bytes of data from this input stream.

Constructors

 o InputStream
 public InputStream()

Methods

 o read
 public abstract int read() throws IOException
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

A subclass must provide an implementation of this method.

Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws: IOException
if an I/O error occurs.
 o read
 public int read(byte b[]) throws IOException
Reads up to b.length bytes of data from this input stream into an array of bytes.

The read method of InputStream calls the read method of three arguments with the arguments b, 0, and b.length.

Parameters:
b - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
Throws: IOException
if an I/O error occurs.
See Also:
read
 o read
 public int read(byte b[],
                 int off,
                 int len) throws IOException
Reads up to len bytes of data from this input stream into an array of bytes. This method blocks until some input is available. If the argument b is null, a NullPointerException is thrown.

The read method of InputStream reads a single byte at a time using the read method of zero arguments to fill in the array. Subclasses are encouraged to provide a more efficient implementation of this method.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
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.
Throws: IOException
if an I/O error occurs.
See Also:
read
 o skip
 public long skip(long n) throws IOException
Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. The actual number of bytes skipped is returned.

The skip method of InputStream creates a byte array of length n and then reads into it until n bytes have been read or the end of the stream has been reached. Subclasses are encouraged to provide a more efficient implementation of this method.

Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws: IOException
if an I/O error occurs.
 o available
 public int available() throws IOException
Returns the number of bytes that can be read from this input stream without blocking. The available method of InputStream returns 0. This method should be overridden by subclasses.

Returns:
the number of bytes that can be read from this input stream without blocking.
Throws: IOException
if an I/O error occurs.
 o close
 public void close() throws IOException
Closes this input stream and releases any system resources associated with the stream.

The close method of InputStream does nothing.

Throws: IOException
if an I/O error occurs.
 o mark
 public synchronized void mark(int readlimit)
Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

The readlimit arguments tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

The mark method of InputStream does nothing.

Parameters:
readlimit - the maximum limit of bytes that can be read before the mark position becomes invalid.
See Also:
reset
 o reset
 public synchronized void reset() throws IOException
Repositions this stream to the position at the time the mark method was last called on this input stream.

The reset method of InputStream throws an IOException, because input streams, by default, do not support mark and reset.

Stream marks are intended to be used in situations where you need to read ahead a little to see what's in the stream. Often this is most easily done by invoking some general parser. If the stream is of the type handled by the parser, it just chugs along happily. If the stream is not of that type, the parser should toss an exception when it fails, which, if it happens within readlimit bytes, allows the outer code to reset the stream and try another parser.

Throws: IOException
if this stream has not been marked or if the mark has been invalidated.
See Also:
mark, IOException
 o markSupported
 public boolean markSupported()
Tests if this input stream supports the mark and reset methods. The markSupported method of InputStream returns false.

Returns:
true if this true type supports the mark and reset method; false otherwise.
See Also:
mark, reset

All Packages  Class Hierarchy  This Package  Previous  Next  Index

Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.