IT. Expert System.

Android Reference

BufferedInputStream


java.io

Class BufferedInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable


    public class BufferedInputStream
    extends FilterInputStream
    Wraps an existing InputStream and buffers the input. Expensive interaction with the underlying input stream is minimized, since most (smaller) requests can be satisfied by accessing the buffer alone. The drawback is that some extra space is required to hold the buffer and that copying takes place when filling that buffer, but this is usually outweighed by the performance benefits.

    A typical application pattern for the class looks like this:

     BufferedInputStream buf = new BufferedInputStream(new FileInputStream("file.java"));
     
    See Also:
    BufferedOutputStream
    • Field Summary

      Fields
      Modifier and Type Field and Description
      protected byte[] buf
      The buffer containing the current bytes read from the target InputStream.
      protected int count
      The total number of bytes inside the byte array buf.
      protected int marklimit
      The current limit, which when passed, invalidates the current mark.
      protected int markpos
      The currently marked position.
      protected int pos
      The current position within the byte array buf.
    • Method Summary

      Methods
      Modifier and Type Method and Description
      int available()
      Returns an estimated number of bytes that can be read or skipped without blocking for more input.
      void close()
      Closes this stream.
      void mark(int readlimit)
      Sets a mark position in this stream.
      boolean markSupported()
      Indicates whether BufferedInputStream supports the mark() and reset() methods.
      int read()
      Reads a single byte from this stream and returns it as an integer in the range from 0 to 255.
      int read(byte[] buffer, int offset, int byteCount)
      Reads at most byteCount bytes from this stream and stores them in byte array buffer starting at offset offset.
      void reset()
      Resets this stream to the last marked location.
      long skip(long byteCount)
      Skips byteCount bytes in this stream.
    • Field Detail

      • buf

        protected volatile byte[] buf
        The buffer containing the current bytes read from the target InputStream.
      • count

        protected int count
        The total number of bytes inside the byte array buf.
      • marklimit

        protected int marklimit
        The current limit, which when passed, invalidates the current mark.
      • markpos

        protected int markpos
        The currently marked position. -1 indicates no mark has been set or the mark has been invalidated.
      • pos

        protected int pos
        The current position within the byte array buf.
    • Constructor Detail

      • BufferedInputStream

        public BufferedInputStream(InputStream in)
        Constructs a new BufferedInputStream, providing in with a buffer of 8192 bytes.

        Warning: passing a null source creates a closed BufferedInputStream. All read operations on such a stream will fail with an IOException.

        Parameters:
        in - the InputStream the buffer reads from.
      • BufferedInputStream

        public BufferedInputStream(InputStream in,
                           int size)
        Constructs a new BufferedInputStream, providing in with size bytes of buffer.

        Warning: passing a null source creates a closed BufferedInputStream. All read operations on such a stream will fail with an IOException.

        Parameters:
        in - the InputStream the buffer reads from.
        size - the size of buffer in bytes.
        Throws:
        IllegalArgumentException - if size <= 0.
    • Method Detail

      • available

        public int available()
                      throws IOException
        Returns an estimated number of bytes that can be read or skipped without blocking for more input. This method returns the number of bytes available in the buffer plus those available in the source stream, but see InputStream.available() for important caveats.
        Overrides:
        available in class FilterInputStream
        Returns:
        the estimated number of bytes available
        Throws:
        IOException - if this stream is closed or an error occurs
      • mark

        public void mark(int readlimit)
        Sets a mark position in this stream. The parameter readlimit indicates how many bytes can be read before a mark is invalidated. Calling reset() will reposition the stream back to the marked position if readlimit has not been surpassed. The underlying buffer may be increased in size to allow readlimit number of bytes to be supported.
        Overrides:
        mark in class FilterInputStream
        Parameters:
        readlimit - the number of bytes that can be read before the mark is invalidated.
        See Also:
        reset()
      • markSupported

        public boolean markSupported()
        Indicates whether BufferedInputStream supports the mark() and reset() methods.
        Overrides:
        markSupported in class FilterInputStream
        Returns:
        true for BufferedInputStreams.
        See Also:
        mark(int), reset()
      • read

        public int read()
                 throws IOException
        Reads a single byte from this stream and returns it as an integer in the range from 0 to 255. Returns -1 if the end of the source string has been reached. If the internal buffer does not contain any available bytes then it is filled from the source stream and the first byte is returned.
        Overrides:
        read in class FilterInputStream
        Returns:
        the byte read or -1 if the end of the source stream has been reached.
        Throws:
        IOException - if this stream is closed or another IOException occurs.
      • read

        public int read(byte[] buffer,
               int offset,
               int byteCount)
                 throws IOException
        Reads at most byteCount bytes from this stream and stores them in byte array buffer starting at offset offset. Returns the number of bytes actually read or -1 if no bytes were read and the end of the stream was encountered. If all the buffered bytes have been used, a mark has not been set and the requested number of bytes is larger than the receiver's buffer size, this implementation bypasses the buffer and simply places the results directly into buffer.
        Overrides:
        read in class FilterInputStream
        Parameters:
        buffer - the byte array in which to store the bytes read.
        offset - the initial position in buffer to store the bytes read from this stream.
        byteCount - the maximum number of bytes to store in buffer.
        Returns:
        the number of bytes actually read or -1 if end of stream.
        Throws:
        IndexOutOfBoundsException - if offset < 0 or byteCount < 0, or if offset + byteCount is greater than the size of buffer.
        IOException - if the stream is already closed or another IOException occurs.
      • reset

        public void reset()
                   throws IOException
        Resets this stream to the last marked location.
        Overrides:
        reset in class FilterInputStream
        Throws:
        IOException - if this stream is closed, no mark has been set or the mark is no longer valid because more than readlimit bytes have been read since setting the mark.
        See Also:
        mark(int)
      • skip

        public long skip(long byteCount)
                  throws IOException
        Skips byteCount bytes in this stream. Subsequent calls to read will not return these bytes unless reset is used.
        Overrides:
        skip in class FilterInputStream
        Parameters:
        byteCount - the number of bytes to skip. skip does nothing and returns 0 if byteCount is less than zero.
        Returns:
        the number of bytes actually skipped.
        Throws:
        IOException - if this stream is closed or another IOException occurs.
        See Also:
        FilterInputStream.mark(int), FilterInputStream.reset()


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 126 / 158697635. Delta: 0.03130 с