public final class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInputStream
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, see 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.
BufferedInputStream| Modifier and Type | Class and Description |
|---|---|
static class |
UnsynchronizedBufferedInputStream.Builder
Builds a new
UnsynchronizedBufferedInputStream instance. |
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns the number of bytes that are available before this stream will block.
|
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 length)
Reads at most
length 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 amount)
Skips
amount number of bytes in this stream. |
builder, readpublic int available()
throws java.io.IOException
available in class UnsynchronizedFilterInputStreamjava.io.IOException - if this stream is closed.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class UnsynchronizedFilterInputStreamjava.io.IOException - if an error occurs while closing this stream.public void mark(int readlimit)
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.mark in class UnsynchronizedFilterInputStreamreadlimit - the number of bytes that can be read before the mark is invalidated.reset()public boolean markSupported()
BufferedInputStream supports the mark() and reset() methods.markSupported in class UnsynchronizedFilterInputStreamtrue for BufferedInputStreams.mark(int),
reset()public int read()
throws java.io.IOException
read in class UnsynchronizedFilterInputStreamjava.io.IOException - if this stream is closed or another IOException occurs.public int read(byte[] buffer,
int offset,
int length)
throws java.io.IOException
length 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.read in class UnsynchronizedFilterInputStreambuffer - the byte array in which to store the bytes read.offset - the initial position in buffer to store the bytes read from this stream.length - the maximum number of bytes to store in buffer.java.lang.IndexOutOfBoundsException - if offset < 0 or length < 0, or if offset + length is greater than the size of buffer.java.io.IOException - if the stream is already closed or another IOException occurs.public void reset()
throws java.io.IOException
reset in class UnsynchronizedFilterInputStreamjava.io.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.mark(int)public long skip(long amount)
throws java.io.IOException
amount number of bytes in this stream. Subsequent read()'s will not return these bytes unless reset() is used.skip in class UnsynchronizedFilterInputStreamamount - the number of bytes to skip. skip does nothing and returns 0 if amount is less than zero.java.io.IOException - if this stream is closed or another IOException occurs.UnsynchronizedFilterInputStream.mark(int),
UnsynchronizedFilterInputStream.reset()Copyright © 2010 - 2023 Adobe. All Rights Reserved