Java BufferedInputStream

www.igi‮ditf‬ea.com

In Java, the BufferedInputStream class is a subclass of the FilterInputStream that provides buffering functionality to an input stream. It reads data from an underlying input stream and stores it in an internal buffer for faster access.

Here are some of the commonly used methods of the BufferedInputStream class:

  1. read(): This method reads a single byte of data from the input stream.

  2. read(byte[] b): This method reads up to b.length bytes of data from the input stream into an array of bytes.

  3. read(byte[] b, int off, int len): This method reads up to len bytes of data from the input stream into an array of bytes starting at the specified offset off.

  4. skip(long n): This method skips over and discards n bytes of data from the input stream.

  5. available(): This method returns an estimate of the number of bytes that can be read from the input stream without blocking.

  6. mark(int readLimit): This method marks the current position in the input stream and sets the read limit to readLimit.

  7. reset(): This method resets the input stream to the position marked by the mark() method.

  8. markSupported(): This method returns a boolean value indicating whether the mark() and reset() methods are supported by the input stream.

  9. close(): This method closes the input stream and releases any system resources associated with it.

It's important to note that the BufferedInputStream class should be used with caution when reading from untrusted sources, as it can be vulnerable to malicious attacks if the data is not properly validated.