Class java.io.BufferedInputStream
All Packages    This Package    Previous    Next

Class java.io.BufferedInputStream

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

public class BufferedInputStream
extends FilterInputStream
A buffered input stream. This stream lets you read characters from a stream without causing a read every time. The data is read into a buffer, subsequent reads result in a fast buffer access.
Version:
1.14, 31 Jan 1995
Author:
Arthur van Hoff

buf
The buffer.
count
The number of bytes in the buffer.
marklimit
The maximum readahead allowed after a mark() before subsequent calls to reset() fail.
markpos
The position in the buffer of the current mark.
pos
The current position in the buffer.

BufferedInputStream(InputStream)
Creates a new buffered stream with a default buffer size.
BufferedInputStream(InputStream, int)
Creates a new buffered stream with a given buffer size.

available()
Returns the number of bytes that can be read without blocking.
mark(int)
Mark the current position in the input stream.
markSupported()
Return true since this stream type supports mark/reset
read()
Reads a byte.
read(byte[], int, int)
Reads into an array of bytes.
reset()
Reposition the stream to the last marked position.
skip(int)
Skips bytes of input.

buf
  protected byte buf[]
The buffer.
count
  protected int count
The number of bytes in the buffer.
pos
  protected int pos
The current position in the buffer.
markpos
  protected int markpos
The position in the buffer of the current mark. -1 if there is no current mark.
marklimit
  protected int marklimit
The maximum readahead allowed after a mark() before subsequent calls to reset() fail.

BufferedInputStream
  public BufferedInputStream(InputStream in)
Creates a new buffered stream with a default buffer size.
Parameters:
in - the input stream

BufferedInputStream

  public BufferedInputStream(InputStream in,
                             int size)
Creates a new buffered stream with a given buffer size.
Parameters:
in - the input stream
size - the buffer size

read
  public synchronized int read()
Reads a byte. Will block if no input is available.
Returns:
the byte read, or -1 if the end of the stream is reached.
Throws: IOException
i/o error occurred
Overrides:
read in class FilterInputStream

read

  public synchronized int read(byte b[],
                               int off,
                               int len)
Reads into an array of bytes. Blocks until some input is available. This method should be overridden in a subclass for efficiency (the default implementation reads 1 byte at a time).
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 actual number of bytes read, -1 is returned when the end of the stream is reached.
Throws: IOException
i/o error occurred
Overrides:
read in class FilterInputStream

skip

  public synchronized int skip(int n)
Skips bytes of input.
Parameters:
n - bytes to be skipped
Returns:
actual number of bytes skipped
Throws: IOException
i/o error occurred
Overrides:
skip in class FilterInputStream

available

  public synchronized int available()
Returns the number of bytes that can be read without blocking. This is the total of the number of bytes in the buffer and the number of bytes available from the input stream.
Returns:
the number of available bytes
Overrides:
available in class FilterInputStream

mark

  public synchronized void mark(int readlimit)
Mark the current position in the input stream. A subsequent call to reset() will reposition the stream at the last marked position so that subsequent reads will re-read the same bytes. The stream promises to allow readlimit bytes to be read before the mark position gets invalidated.
Overrides:
mark in class FilterInputStream

reset

  public synchronized void reset()
Reposition the stream to the last marked position. If the stream has not been marked, or if the mark has been invalidated, an IOException is thrown. 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 parse, 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.
Overrides:
reset in class FilterInputStream

markSupported

  public boolean markSupported()
Return true since this stream type supports mark/reset
Overrides:
markSupported in class FilterInputStream


All Packages    This Package    Previous    Next