|
Java EE 5 SDK | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream java.io.FilterInputStream java.io.BufferedInputStream javax.mail.util.SharedFileInputStream
public class SharedFileInputStream
A 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.
Field Summary | |
---|---|
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. |
protected RandomAccessFile |
in
The file containing the data. |
protected long |
start
The file offset of the start of data in this subset of the file. |
Fields inherited from class java.io.BufferedInputStream |
---|
buf, count, marklimit, markpos, pos |
Constructor Summary | |
---|---|
SharedFileInputStream(File file)
Creates a SharedFileInputStream
for the file. |
|
SharedFileInputStream(File file,
int size)
Creates a SharedFileInputStream
with the specified buffer size. |
|
SharedFileInputStream(String file)
Creates a SharedFileInputStream
for the named file |
|
SharedFileInputStream(String file,
int size)
Creates a SharedFileInputStream
with the specified buffer size. |
Method Summary | |
---|---|
int |
available()
Returns the number of bytes that can be read from this input stream without blocking. |
void |
close()
Closes this input stream and releases any system resources associated with the stream. |
protected void |
finalize()
Force this stream to close. |
long |
getPosition()
Return the current position in the InputStream, as an offset from the beginning of the InputStream. |
void |
mark(int readlimit)
See the general contract of the mark
method of InputStream . |
boolean |
markSupported()
Tests if this input stream supports the mark
and reset methods. |
InputStream |
newStream(long start,
long end)
Return a new InputStream representing a subset of the data from this InputStream, starting at start (inclusive)
up to end (exclusive). |
int |
read()
See the general contract of the read
method of InputStream . |
int |
read(byte[] b,
int off,
int len)
Reads bytes from this stream into the specified byte array, starting at the given offset. |
void |
reset()
See the general contract of the reset
method of InputStream . |
long |
skip(long n)
See the general contract of the skip
method of InputStream . |
Methods inherited from class java.io.FilterInputStream |
---|
read |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected RandomAccessFile in
protected int bufsize
protected long bufpos
protected long start
protected long datalen
Constructor Detail |
---|
public SharedFileInputStream(File file) throws IOException
SharedFileInputStream
for the file.
file
- the file
IOException
public SharedFileInputStream(String file) throws IOException
SharedFileInputStream
for the named file
file
- the file
IOException
public SharedFileInputStream(File file, int size) throws IOException
SharedFileInputStream
with the specified buffer size.
file
- the filesize
- the buffer size.
IllegalArgumentException
- if size <= 0.
IOException
public SharedFileInputStream(String file, int size) throws IOException
SharedFileInputStream
with the specified buffer size.
file
- the filesize
- the buffer size.
IllegalArgumentException
- if size <= 0.
IOException
Method Detail |
---|
public int read() throws IOException
read
method of InputStream
.
read
in class BufferedInputStream
-1
if the end of the
stream is reached.
IOException
- if an I/O error occurs.public int read(byte[] b, int off, int len) throws IOException
This method implements the general contract of the corresponding
method of the read
class.
InputStream
read
in class BufferedInputStream
b
- destination buffer.off
- offset at which to start storing bytes.len
- maximum number of bytes to read.
-1
if the end of
the stream has been reached.
IOException
- if an I/O error occurs.public long skip(long n) throws IOException
skip
method of InputStream
.
skip
in class BufferedInputStream
n
- the number of bytes to be skipped.
IOException
- if an I/O error occurs.public int available() throws IOException
available
in class BufferedInputStream
IOException
- if an I/O error occurs.public void mark(int readlimit)
mark
method of InputStream
.
mark
in class BufferedInputStream
readlimit
- the maximum limit of bytes that can be read before
the mark position becomes invalid.reset()
public void reset() throws IOException
reset
method of InputStream
.
If markpos
is -1
(no mark has been set or the mark has been
invalidated), an IOException
is thrown. Otherwise, pos
is
set equal to markpos
.
reset
in class BufferedInputStream
IOException
- if this stream has not been marked or
if the mark has been invalidated.mark(int)
public boolean markSupported()
mark
and reset
methods. The markSupported
method of SharedFileInputStream
returns
true
.
markSupported
in class BufferedInputStream
boolean
indicating if this stream type supports
the mark
and reset
methods.InputStream.mark(int)
,
InputStream.reset()
public void close() throws IOException
close
in interface Closeable
close
in class BufferedInputStream
IOException
- if an I/O error occurs.public long getPosition()
getPosition
in interface SharedInputStream
public InputStream newStream(long start, long end)
start
(inclusive)
up to end
(exclusive). start
must be
non-negative. If end
is -1, the new stream ends
at the same place as this stream. The returned InputStream
will also implement the SharedInputStream interface.
newStream
in interface SharedInputStream
start
- the starting positionend
- the ending position + 1
protected void finalize() throws Throwable
|
Java EE 5 SDK | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 2006 Sun Microsystems, Inc. All rights reserved.