|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.mail.util Class SharedFileInputStream
java.lang.Object java.io.InputStream java.io.FilterInputStream java.io.BufferedInputStream javax.mail.util.SharedFileInputStream
- All Implemented Interfaces:
- Closeable, SharedInputStream
public class SharedFileInputStream
- extends BufferedInputStream
- implements SharedInputStream
SharedFileInputStream
是一个 BufferedInputStream
,对来自文件的数据进行缓冲并支持 mark
和 reset
方法。它也支持 newStream
方法,该方法允许创建表示文件子集的其他流。RandomAccessFile
对象用于访问文件数据。
注意,当 SharedFileInputStream 关闭时,使用 newStream
方法创建的所有流也会关闭。这允许 SharedFileInputStream 对象的创建者控制对底层文件的访问,并确保在必要时底层文件是关闭的,以避免泄漏文件描述符。还要注意,此行为与 SharedInputStream 的要求存在冲突,在以后的版本中可能更改。
since |
|
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.
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.
- Since:
- JavaMail 1.4
- Author:
- Bill Shannon
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 |
---|
英文文档:
in
protected RandomAccessFile in
- The file containing the data.
Shared by all related SharedFileInputStreams.
英文文档:
bufsize
protected int bufsize
- The normal size of the read buffer.
英文文档:
bufpos
protected long bufpos
- The file offset that corresponds to the first byte in
the read buffer.
英文文档:
start
protected long start
- The file offset of the start of data in this subset of the file.
英文文档:
datalen
protected long datalen
- The amount of data in this subset of the file.
Constructor Detail |
---|
public
SharedFileInputStream(java.io.File file) throws java.io.IOException
为文件创建一个 SharedFileInputStream
。
file | 文件 |
SharedFileInputStream
public SharedFileInputStream(File file) throws IOException
- Creates a
SharedFileInputStream
for the file.- Parameters:
file
- the file- Throws:
IOException
public
SharedFileInputStream(String file) throws java.io.IOException
为指定文件创建一个 SharedFileInputStream
。
file | 文件 |
SharedFileInputStream
public SharedFileInputStream(String file) throws IOException
- Creates a
SharedFileInputStream
for the named file- Parameters:
file
- the file- Throws:
IOException
public
SharedFileInputStream(java.io.File file, int size) throws java.io.IOException
创建一个具有指定缓冲区大小的 SharedFileInputStream
。
file | 文件 |
size | 缓冲区的大小。 |
Throws | IllegalArgumentException: 如果 size <= 0 |
SharedFileInputStream
public SharedFileInputStream(File file, int size) throws IOException
- Creates a
SharedFileInputStream
with the specified buffer size.- Parameters:
file
- the filesize
- the buffer size.- Throws:
IllegalArgumentException
- if size <= 0.IOException
public
SharedFileInputStream(String file, int size) throws java.io.IOException
创建一个具有指定缓冲区大小的 SharedFileInputStream
。
file | 文件 |
size | 缓冲区的大小。 |
Throws | IllegalArgumentException: 如果 size <= 0 |
SharedFileInputStream
public SharedFileInputStream(String file, int size) throws IOException
- Creates a
SharedFileInputStream
with the specified buffer size.- Parameters:
file
- the filesize
- the buffer size.- Throws:
IllegalArgumentException
- if size <= 0.IOException
Method Detail |
---|
public int
read() throws java.io.IOException
参见 InputStream
的 read
方法的常规协定。
return |
下一个数据字节,如果到达流末尾,则返回 -1 。 |
Throws | java.io.IOException: 如果发生 I/O 错误。 |
read
public int read() throws IOException
- See the general contract of the
read
method ofInputStream
. - Overrides:
read
in classBufferedInputStream
- Returns:
- the next byte of data, or
-1
if the end of the stream is reached. - Throws:
IOException
- if an I/O error occurs.
public int
read(byte[] b, int off, int len) throws java.io.IOException
从此流中给定的偏移量处读取各字节并存入指定的 byte 数组中。
此方法实现 java.io.InputStream
类相应 read
方法的常规协定。
b | 目标缓冲区。 |
off | 开始存储字节处的偏移量。 |
len | 要读取的最大字节数。 |
return |
读取的字节数;如果已到达流末尾,则返回 -1 。 |
Throws | java.io.IOException: 如果发生 I/O 错误。 |
read
public int read(byte[] b, int off, int len) throws IOException
- Reads bytes from this stream into the specified byte array,
starting at the given offset.
This method implements the general contract of the corresponding
read
method of theInputStream
class. - Overrides:
read
in classBufferedInputStream
- Parameters:
b
- destination buffer.off
- offset at which to start storing bytes.len
- maximum number of bytes to read.- Returns:
- the number of bytes read, or
-1
if the end of the stream has been reached. - Throws:
IOException
- if an I/O error occurs.
public long
skip(long n) throws java.io.IOException
参见 InputStream
的 skip
方法的常规协定。
n | 要跳过的字节数。 |
return | 跳过的实际字节数。 |
Throws | java.io.IOException: 如果发生 I/O 错误。 |
skip
public long skip(long n) throws IOException
- See the general contract of the
skip
method ofInputStream
. - Overrides:
skip
in classBufferedInputStream
- Parameters:
n
- the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException
- if an I/O error occurs.
public int
available() throws java.io.IOException
返回可以不受阻塞地从此输入流中读取的字节数。
return | 不发生阻塞地从此输入流读取的字节数。 |
Throws | java.io.IOException: 如果发生 I/O 错误。 |
available
public int available() throws IOException
- Returns the number of bytes that can be read from this input
stream without blocking.
- Overrides:
available
in classBufferedInputStream
- Returns:
- the number of bytes that can be read from this input stream without blocking.
- Throws:
IOException
- if an I/O error occurs.
public void
mark(int readlimit)
参见 InputStream
的 mark
方法的常规协定。
readlimit | 在标记位置变为无效之前可以读取字节的最大限制。 |
See also | reset() |
mark
public void mark(int readlimit)
- See the general contract of the
mark
method ofInputStream
. - Overrides:
mark
in classBufferedInputStream
- Parameters:
readlimit
- the maximum limit of bytes that can be read before the mark position becomes invalid.- See Also:
reset()
public void
reset() throws java.io.IOException
参见 InputStream
的 reset
方法的常规协定。
如果 markpos
为 -1
(尚未设置标记,或者标记已失效),则抛出 IOException
。否则将 pos
设置为与 markpos
相等。
Throws | java.io.IOException: 如果未标记此流或该标记失效。 |
See also | mark(int) |
reset
public void reset() throws IOException
- See the general contract of the
reset
method ofInputStream
.If
markpos
is-1
(no mark has been set or the mark has been invalidated), anIOException
is thrown. Otherwise,pos
is set equal tomarkpos
. - Overrides:
reset
in classBufferedInputStream
- Throws:
IOException
- if this stream has not been marked or if the mark has been invalidated.- See Also:
mark(int)
public boolean
markSupported()
测试此输入流是否支持 mark
和 reset
方法。SharedFileInputStream
的 markSupported
方法返回 true
。
return |
一个 boolean 值,指示此流类型是否支持 mark 和 reset 方法。 |
See also | mark(int), reset() |
markSupported
public boolean markSupported()
- Tests if this input stream supports the
mark
andreset
methods. ThemarkSupported
method ofSharedFileInputStream
returnstrue
. - Overrides:
markSupported
in classBufferedInputStream
- Returns:
- a
boolean
indicating if this stream type supports themark
andreset
methods. - See Also:
InputStream.mark(int)
,InputStream.reset()
public void
close() throws java.io.IOException
关闭此输入流并释放与该流关联的所有系统资源。
Throws | java.io.IOException: 如果发生 I/O 错误。 |
close
public void close() throws IOException
- Closes this input stream and releases any system resources
associated with the stream.
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classBufferedInputStream
- Throws:
IOException
- if an I/O error occurs.
public long
getPosition()
返回 InputStream 中的当前位置,形式为距 InputStream 开头的偏移量。
return | 当前位置 |
getPosition
public long getPosition()
- Return the current position in the InputStream, as an
offset from the beginning of the InputStream.
- Specified by:
getPosition
in interfaceSharedInputStream
- Returns:
- the current position
public java.io.InputStream
newStream(long start, long end)
返回表示此 InputStream 数据的子集的新 InputStream,从 start
(包括)开始,一直到 end
(不包括)结束。start
必须为非负数。如果 end
为 -1,则新流的结束位置与此流相同。返回的 InputStream 也将实现 SharedInputStream 接口。
start | 起始位置 |
end | 结束位置 + 1 |
return | 新流 |
newStream
public InputStream newStream(long start, long end)
- Return a new InputStream representing a subset of the data
from this InputStream, starting at
start
(inclusive) up toend
(exclusive).start
must be non-negative. Ifend
is -1, the new stream ends at the same place as this stream. The returned InputStream will also implement the SharedInputStream interface. - Specified by:
newStream
in interfaceSharedInputStream
- Parameters:
start
- the starting positionend
- the ending position + 1- Returns:
- the new stream
protected void
finalize() throws Throwable
强制关闭此流。
英文文档:
finalize
protected void finalize() throws Throwable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!