SharedFileInputStream (Java EE 5 SDK)

Java

Java EE 5 SDK

深圳电信培训中心.徐海蛟老师.


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
所有已实现的接口:
Closeable, SharedInputStream

public class SharedFileInputStream
extends BufferedInputStream
implements 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.

从以下版本开始:
JavaMail 1.4
作者:
Bill Shannon

字段摘要
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
 
构造器摘要
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.
 
方法摘要
 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.
 
类方法继承 java.io.FilterInputStream
read
 
类方法继承 java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

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.

构造器详细信息

SharedFileInputStream

public SharedFileInputStream(File file)
                      throws IOException
Creates a SharedFileInputStream for the file.

参数:
file - the file
抛出异常:
IOException


SharedFileInputStream

public SharedFileInputStream(String file)
                      throws IOException
Creates a SharedFileInputStream for the named file

参数:
file - the file
抛出异常:
IOException


SharedFileInputStream

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

参数:
file - the file
size - the buffer size.
抛出异常:
IllegalArgumentException - if size <= 0.
IOException


SharedFileInputStream

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

参数:
file - the file
size - the buffer size.
抛出异常:
IllegalArgumentException - if size <= 0.
IOException

方法详细信息

read

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

重写:
read in class BufferedInputStream
返回:
the next byte of data, or -1 if the end of the stream is reached.
抛出异常:
IOException - if an I/O error occurs.

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.

重写:
read in class BufferedInputStream
参数:
b - destination buffer.
off - offset at which to start storing bytes.
len - maximum number of bytes to read.
返回:
the number of bytes read, or -1 if the end of the stream has been reached.
抛出异常:
IOException - if an I/O error occurs.

skip

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

重写:
skip in class BufferedInputStream
参数:
n - the number of bytes to be skipped.
返回:
the actual number of bytes skipped.
抛出异常:
IOException - if an I/O error occurs.

available

public int available()
              throws IOException
Returns the number of bytes that can be read from this input stream without blocking.

重写:
available in class BufferedInputStream
返回:
the number of bytes that can be read from this input stream without blocking.
抛出异常:
IOException - if an I/O error occurs.

mark

public void mark(int readlimit)
See the general contract of the 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()

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.

重写:
reset in class BufferedInputStream
抛出异常:
IOException - if this stream has not been marked or if the mark has been invalidated.
另请参见:
mark(int)

markSupported

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

重写:
markSupported in class BufferedInputStream
返回:
a boolean indicating if this stream type supports the mark and reset methods.
另请参见:
InputStream.mark(int), InputStream.reset()

close

public void close()
           throws IOException
Closes this input stream and releases any system resources associated with the stream.

规范说明:
close in interface Closeable
重写:
close in class BufferedInputStream
抛出异常:
IOException - if an I/O error occurs.

getPosition

public long getPosition()
Return the current position in the InputStream, as an offset from the beginning of the InputStream.

规范说明:
getPosition in interface SharedInputStream
返回:
the current position

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.

规范说明:
newStream in interface SharedInputStream
参数:
start - the starting position
end - the ending position + 1
返回:
the new stream

finalize

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

重写:
finalize in class Object
抛出异常:
Throwable

Java EE 5 SDK

深圳电信培训中心.徐海蛟老师.


提交错误或意见

版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。深圳电信培训中心.徐海蛟老师教学参考.