Package org.apache.commons.io.input
Class UnsynchronizedBufferedInputStream
java.lang.Object
java.io.InputStream
org.apache.commons.io.input.UnsynchronizedFilterInputStream
org.apache.commons.io.input.UnsynchronizedBufferedInputStream
- All Implemented Interfaces:
- Closeable,- AutoCloseable
An unsynchronized version of 
BufferedInputStream, not thread-safe.
 
 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.
 
 To build an instance, use UnsynchronizedBufferedInputStream.Builder.
 
A typical application pattern for the class looks like this:
 UnsynchronizedBufferedInputStream s = new UnsynchronizedBufferedInputStream.Builder().
   .setInputStream(new FileInputStream("file.java"))
   .setBufferSize(8192)
   .get();
 
 Provenance: Apache Harmony and modified.
- Since:
- 2.12.0
- See Also:
- 
Nested Class SummaryNested Classes
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected byte[]The buffer containing the current bytes read from the target InputStream.protected intThe total number of bytes inside the byte arraybuffer.protected intThe current limit, which when passed, invalidates the current mark.protected intThe currently marked position. -1 indicates no mark has been set or the mark has been invalidated.protected intThe current position within the byte arraybuffer.Fields inherited from class org.apache.commons.io.input.UnsynchronizedFilterInputStreaminputStream
- 
Method SummaryModifier and TypeMethodDescriptionintReturns the number of bytes that are available before this stream will block.voidclose()Closes this stream.voidmark(int readLimit) Sets a mark position in this stream.booleanIndicates whetherBufferedInputStreamsupports themark()andreset()methods.intread()Reads a single byte from this stream and returns it as an integer in the range from 0 to 255.intread(byte[] dest, int offset, int length) Reads at mostlengthbytes from this stream and stores them in byte arraybufferstarting at offsetoffset.voidreset()Resets this stream to the last marked location.longskip(long amount) Skipsamountnumber of bytes in this stream.Methods inherited from class org.apache.commons.io.input.UnsynchronizedFilterInputStreambuilder, read
- 
Field Details- 
bufferThe buffer containing the current bytes read from the target InputStream.
- 
countThe total number of bytes inside the byte arraybuffer.
- 
markLimitThe current limit, which when passed, invalidates the current mark.
- 
markPosThe currently marked position. -1 indicates no mark has been set or the mark has been invalidated.
- 
posThe current position within the byte arraybuffer.
 
- 
- 
Method Details- 
availableReturns the number of bytes that are available before this stream will block. This method returns the number of bytes available in the buffer plus those available in the source stream.- Overrides:
- availablein class- UnsynchronizedFilterInputStream
- Returns:
- the number of bytes available before blocking.
- Throws:
- IOException- if this stream is closed.
 
- 
closeCloses this stream. The source stream is closed and any resources associated with it are released.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- UnsynchronizedFilterInputStream
- Throws:
- IOException- if an error occurs while closing this stream.
 
- 
markSets a mark position in this stream. The parameterreadLimitindicates how many bytes can be read before a mark is invalidated. Callingreset()will reposition the stream back to the marked position ifreadLimithas not been surpassed. The underlying buffer may be increased in size to allowreadLimitnumber of bytes to be supported.- Overrides:
- markin class- UnsynchronizedFilterInputStream
- Parameters:
- readLimit- the number of bytes that can be read before the mark is invalidated.
- See Also:
 
- 
markSupportedIndicates whetherBufferedInputStreamsupports themark()andreset()methods.- Overrides:
- markSupportedin class- UnsynchronizedFilterInputStream
- Returns:
- truefor BufferedInputStreams.
- See Also:
 
- 
readReads 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:
- readin class- UnsynchronizedFilterInputStream
- 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.
 
- 
readReads at mostlengthbytes from this stream and stores them in byte arraybufferstarting at offsetoffset. 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 intobuffer.- Overrides:
- readin class- UnsynchronizedFilterInputStream
- Parameters:
- dest- the byte array in which to store the bytes read.
- offset- the initial position in- bufferto store the bytes read from this stream.
- length- 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 < 0or- length < 0, or if- offset + lengthis greater than the size of- buffer.
- IOException- if the stream is already closed or another IOException occurs.
 
- 
resetResets this stream to the last marked location.- Overrides:
- resetin class- UnsynchronizedFilterInputStream
- Throws:
- IOException- if this stream is closed, no mark has been set or the mark is no longer valid because more than- readLimitbytes have been read since setting the mark.
- See Also:
 
- 
skipSkipsamountnumber of bytes in this stream. Subsequentread()'s will not return these bytes unlessreset()is used.- Overrides:
- skipin class- UnsynchronizedFilterInputStream
- Parameters:
- amount- the number of bytes to skip.- skipdoes nothing and returns 0 if- amountis less than zero.
- Returns:
- the number of bytes actually skipped.
- Throws:
- IOException- if this stream is closed or another IOException occurs.
- See Also:
 
 
-