SharedFileInputStream (Java EE 5)

Java EE API


javax.mail.util Class SharedFileInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.BufferedInputStream
              extended by javax.mail.util.SharedFileInputStream
All Implemented Interfaces:
Closeable, SharedInputStream

public class SharedFileInputStream
extends BufferedInputStream
implements SharedInputStream

Extends: java.io.InputStream > java.io.FilterInputStream > java.io.BufferedInputStream
Implements: SharedInputStream

SharedFileInputStream 是一个 BufferedInputStream,对来自文件的数据进行缓冲并支持 markreset 方法。它也支持 newStream 方法,该方法允许创建表示文件子集的其他流。RandomAccessFile 对象用于访问文件数据。

注意,当 SharedFileInputStream 关闭时,使用 newStream 方法创建的所有流也会关闭。这允许 SharedFileInputStream 对象的创建者控制对底层文件的访问,并确保在必要时底层文件是关闭的,以避免泄漏文件描述符。还要注意,此行为与 SharedInputStream 的要求存在冲突,在以后的版本中可能更改。

英文文档:

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
protected  int
protected  long
protected  RandomAccessFile
protected  long
 
Fields inherited from class java.io.BufferedInputStream
 
Constructor Summary
 
Method Summary
 int
 void
protected  void
 long
 void
 boolean
 InputStream
 int
 int
 void
 long
 
Methods inherited from class java.io.FilterInputStream
 
Methods inherited from class java.lang.Object
 

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 缓冲区的大小。
ThrowsIllegalArgumentException: 如果 size <= 0
英文文档:

SharedFileInputStream

public SharedFileInputStream(File file,
                             int size)
                      throws IOException
Creates a SharedFileInputStream with the specified buffer size.

Parameters:
file - the file
size - the buffer size.
Throws:
IllegalArgumentException - if size <= 0.
IOException


public SharedFileInputStream(String file, int size) throws java.io.IOException
创建一个具有指定缓冲区大小的 SharedFileInputStream
file 文件
size 缓冲区的大小。
ThrowsIllegalArgumentException: 如果 size <= 0
英文文档:

SharedFileInputStream

public SharedFileInputStream(String file,
                             int size)
                      throws IOException
Creates a SharedFileInputStream with the specified buffer size.

Parameters:
file - the file
size - the buffer size.
Throws:
IllegalArgumentException - if size <= 0.
IOException

Method Detail

public int read() throws java.io.IOException
参见 InputStreamread 方法的常规协定。
return 下一个数据字节,如果到达流末尾,则返回 -1
Throwsjava.io.IOException: 如果发生 I/O 错误。
英文文档:

read

public int read()
         throws IOException
See the general contract of the read method of InputStream.

Overrides:
read in class BufferedInputStream
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
Throwsjava.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 the InputStream class.

Overrides:
read in class BufferedInputStream
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
参见 InputStreamskip 方法的常规协定。
n 要跳过的字节数。
return 跳过的实际字节数。
Throwsjava.io.IOException: 如果发生 I/O 错误。
英文文档:

skip

public long skip(long n)
          throws IOException
See the general contract of the skip method of InputStream.

Overrides:
skip in class BufferedInputStream
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 不发生阻塞地从此输入流读取的字节数。
Throwsjava.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 class BufferedInputStream
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)
参见 InputStreammark 方法的常规协定。
readlimit 在标记位置变为无效之前可以读取字节的最大限制。
See also reset()
英文文档:

mark

public void mark(int readlimit)
See the general contract of the mark method of InputStream.

Overrides:
mark in class BufferedInputStream
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
参见 InputStreamreset 方法的常规协定。

如果 markpos-1(尚未设置标记,或者标记已失效),则抛出 IOException。否则将 pos 设置为与 markpos 相等。

Throwsjava.io.IOException: 如果未标记此流或该标记失效。
See also mark(int)

英文文档:

reset

public void reset()
           throws IOException
See the general contract of the 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.

Overrides:
reset in class BufferedInputStream
Throws:
IOException - if this stream has not been marked or if the mark has been invalidated.
See Also:
mark(int)

public boolean markSupported()
测试此输入流是否支持 markreset 方法。SharedFileInputStreammarkSupported 方法返回 true
return 一个 boolean 值,指示此流类型是否支持 markreset 方法。
See also mark(int), reset()
英文文档:

markSupported

public boolean markSupported()
Tests if this input stream supports the mark and reset methods. The markSupported method of SharedFileInputStream returns true.

Overrides:
markSupported in class BufferedInputStream
Returns:
a boolean indicating if this stream type supports the mark and reset methods.
See Also:
InputStream.mark(int), InputStream.reset()

public void close() throws java.io.IOException
关闭此输入流并释放与该流关联的所有系统资源。
Throwsjava.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 interface Closeable
Overrides:
close in class BufferedInputStream
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 interface SharedInputStream
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 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.

Specified by:
newStream in interface SharedInputStream
Parameters:
start - the starting position
end - the ending position + 1
Returns:
the new stream

protected void finalize() throws Throwable
强制关闭此流。
英文文档:

finalize

protected void finalize()
                 throws Throwable
Force this stream to close.

Overrides:
finalize in class Object
Throws:
Throwable


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!