SharedFileInputStream is a
BufferedInputStream that buffers
data from the file and supports the mark
and reset methods. It also supports the
newStream method that allows you to create
other streams that represent subsets of the file.
A RandomAccessFile object is used to
access the file data.
Note that when the SharedFileInputStream is closed,
all streams created with the newStream
method are also closed. This allows the creator of the
SharedFileInputStream object to control access to the
underlying file and ensure that it is closed when
needed, to avoid leaking file descriptors. Note also
that this behavior contradicts the requirements of
SharedInputStream and may change in a future release.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | SharedFileInputStream.SharedFile
A shared class that keeps track of the references to a particular file so it can be closed when the last reference is gone. |
| Modifier and Type | Field and Description |
|---|---|
| protected long | bufpos
The file offset that corresponds to the first byte in the read buffer. |
| protected int | bufsize
The normal size of the read buffer. |
| protected long | datalen
The amount of data in this subset of the file. |
| private static int | |
| protected RandomAccessFile | in
Hides java. |
| private boolean | master
True if this is a top level stream created directly by "new". |
| private SharedFileInputStream. | |
| protected long | start
The file offset of the start of data in this subset of the file. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | SharedFileInputStream(File
the file file, int the buffer size. size)Creates a |
| public | SharedFileInputStream(String
the file file, int the buffer size. size)Creates a |
| private | SharedFileInputStream(SharedFileInputStream.
Used internally by the |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized int | Returns: the number of bytes that can be read from this input stream without blocking.Overrides java. |
| public void | close()
Overrides java. Implements java. |
| private void | ensureOpen()
Check to make sure that this stream has not been closed
|
| private void | fill()
Fills the buffer with more data, taking into account
shuffling and other tricks for dealing with marks.
|
| protected void | |
| public long | Returns: the current positionImplements javax. |
| private int | |
| private void | |
| public synchronized void | mark(int
the maximum limit of bytes that can be read before
the mark position becomes invalid. readlimit)Overrides java. mark
method of InputStream.
|
| public boolean | Returns: aboolean indicating if this stream type supports
the mark and reset methods.Overrides java. mark
and reset methods.
|
| public synchronized InputStream | Returns: the new streamthe starting position start, long the ending position + 1 end)Implements javax. start (inclusive)
up to end (exclusive).
|
| public synchronized int | Returns: the next byte of data, or-1 if the end of the
stream is reached.Overrides java. read
method of InputStream.
|
| public synchronized int | Returns: the number of bytes read, or-1 if the end of
the stream has been reached.destination buffer. b, int offset at which to start storing bytes. off, int maximum number of bytes to read. len)Overrides java. |
| private int | read1(byte[] b, int off, int len)
Read characters into a portion of an array, reading from the underlying
stream at most once if necessary.
|
| public synchronized void | reset()
Overrides java. reset
method of InputStream.
|
| public synchronized long | Returns: the actual number of bytes skipped.the number of bytes to be skipped. n)Overrides java. skip
method of InputStream.
|
| bufpos | back to summary |
|---|---|
| protected long bufpos The file offset that corresponds to the first byte in the read buffer. | |
| bufsize | back to summary |
|---|---|
| protected int bufsize The normal size of the read buffer. | |
| datalen | back to summary |
|---|---|
| protected long datalen The amount of data in this subset of the file. | |
| defaultBufferSize | back to summary |
|---|---|
| private static int defaultBufferSize | |
| in | back to summary |
|---|---|
| protected RandomAccessFile in Hides java. The file containing the data. Shared by all related SharedFileInputStreams. | |
| master | back to summary |
|---|---|
| private boolean master True if this is a top level stream created directly by "new". False if this is a derived stream created by newStream. | |
| sf | back to summary |
|---|---|
| private SharedFileInputStream. | |
| start | back to summary |
|---|---|
| protected long start The file offset of the start of data in this subset of the file. | |
| SharedFileInputStream | back to summary |
|---|---|
| public SharedFileInputStream(File file) throws IOException Creates a
| |
| SharedFileInputStream | back to summary |
|---|---|
| public SharedFileInputStream(String file) throws IOException Creates a
| |
| SharedFileInputStream | back to summary |
|---|---|
| public SharedFileInputStream(File file, int size) throws IOException Creates a
| |
| SharedFileInputStream | back to summary |
|---|---|
| public SharedFileInputStream(String file, int size) throws IOException Creates a
| |
| SharedFileInputStream | back to summary |
|---|---|
| private SharedFileInputStream(SharedFileInputStream. Used internally by the | |
| available | back to summary |
|---|---|
| public synchronized int available() throws IOException Overrides java. Returns the number of bytes that can be read from this input stream without blocking.
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Closes this input stream and releases any system resources associated with the stream.
| |
| ensureOpen | back to summary |
|---|---|
| private void ensureOpen() throws IOException Hides java. Check to make sure that this stream has not been closed | |
| fill | back to summary |
|---|---|
| private void fill() throws IOException Hides java. Fills the buffer with more data, taking into account shuffling and other tricks for dealing with marks. Assumes that it is being called by a synchronized method. This method also assumes that all data has already been read in, hence pos > count. | |
| finalize | back to summary |
|---|---|
| protected void finalize() throws Throwable Overrides java. Force this stream to close.
| |
| getPosition | back to summary |
|---|---|
| public long getPosition() Implements javax. Return the current position in the InputStream, as an offset from the beginning of the InputStream.
| |
| in_available | back to summary |
|---|---|
| private int in_available() throws IOException | |
| init | back to summary |
|---|---|
| private void init(SharedFileInputStream. | |
| mark | back to summary |
|---|---|
| public synchronized void mark(int readlimit) Overrides java. See the general contract of the | |
| markSupported | back to summary |
|---|---|
| public boolean markSupported() Overrides java. Tests if this input stream supports the
| |
| newStream | back to summary |
|---|---|
| public synchronized InputStream newStream(long start, long end) Implements javax. Return a new InputStream representing a subset of the data
from this InputStream, starting at
| |
| read | back to summary |
|---|---|
| public synchronized int read() throws IOException Overrides java. See the general contract of the
| |
| read | back to summary |
|---|---|
| public synchronized int read(byte[] b, int off, int len) throws IOException Overrides java. Reads bytes from this stream into the specified byte array, starting at the given offset. This method implements the general contract of the corresponding
| |
| read1 | back to summary |
|---|---|
| private int read1(byte[] b, int off, int len) throws IOException Hides java. Read characters into a portion of an array, reading from the underlying stream at most once if necessary. | |
| reset | back to summary |
|---|---|
| public synchronized void reset() throws IOException Overrides java. See the general contract of the
If
| |
| skip | back to summary |
|---|---|
| public synchronized long skip(long n) throws IOException Overrides java. See the general contract of the
| |