|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.io.InputStream
java.io.FilterInputStream
javax.crypto.CipherInputStream
public class CipherInputStream
CipherInputStream 由一个 InputStream 和一个 Cipher 组成,这样 read() 方法才能返回从底层 InputStream 读入但已经由该 Cipher 另外处理过的数据。在由 CipherInputStream 使用之前,该 Cipher 必须充分初始化。
例如,假设 Cipher 初始化为解密,在返回解密的数据之前,CipherInputStream 将尝试读入数据并将其解密。
此类严格遵守此语义,尤其是其祖先类 java.io.FilterInputStream 和 java.io.InputStream 的失败语义。此类具有在其祖先类中指定的所有方法,并且对所有的这些方法进行了重写。除此之外,此类还对其祖先类未抛出的所有异常进行捕获。特别地,skip 方法跳过,available 方法只计算已由封装的 Cipher 处理过的数据。
对程序员非常重要的一点是,请不要使用未在此类中定义或重写的方法(例如,后来加入到其超类之一中的新方法或构造方法),因为那些方法的设计和实现可能未考虑到对 CipherInputStream 的安全影响。
InputStream,
FilterInputStream,
Cipher,
CipherOutputStream| 字段摘要 |
|---|
| 从类 java.io.FilterInputStream 继承的字段 |
|---|
in |
| 构造方法摘要 | |
|---|---|
protected |
CipherInputStream(InputStream is)
根据 InputStream 构造 CipherInputStream,不指定 Cipher。 |
|
CipherInputStream(InputStream is,
Cipher c)
根据 InputStream 和 Cipher 构造 CipherInputStream。 |
| 方法摘要 | |
|---|---|
int |
available()
返回不发生阻塞地从此输入流读取的字节数。 |
void |
close()
关闭该输入流并释放任何与该流关联的系统资源。 |
boolean |
markSupported()
测试该输入流是否支持 mark 和 reset 方法以及哪一个方法确实不受支持。 |
int |
read()
从该输入流读取下一数据字节。 |
int |
read(byte[] b)
从该输入流将 b.length 个数据字节读入到字节数组中。 |
int |
read(byte[] b,
int off,
int len)
从该输入流将 len 个字节数据读入到字节数组中。 |
long |
skip(long n)
跳过不发生阻塞地从该输入流读取的字节中的 n 个字节的输入。 |
| 从类 java.io.FilterInputStream 继承的方法 |
|---|
mark, reset |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 构造方法详细信息 |
|---|
public CipherInputStream(InputStream is,
Cipher c)
is - 将被处理的输入流c - 已初始化的 Cipher 对象protected CipherInputStream(InputStream is)
is - 将被处理的输入流| 方法详细信息 |
|---|
public int read()
throws IOException
0 到 255 范围内的 int 字节值。如果因为到达流末尾而没有可用的字节,则返回值 -1。在输入数据可用、检测到流末尾或抛出异常之前,此方法将一直阻塞。
FilterInputStream 中的 read-1。
IOException - 如果发生 I/O 错误。FilterInputStream.in
public int read(byte[] b)
throws IOException
b.length 个数据字节读入到字节数组中。
InputStream 的 read 方法将 b、0 和 b.length 作为三个参数来调用 read 方法。
FilterInputStream 中的 readb - 存储读入数据的缓冲区。
-1。
IOException - 如果发生 I/O 错误。InputStream.read(byte[], int, int)
public int read(byte[] b,
int off,
int len)
throws IOException
len 个字节数据读入到字节数组中。在某些输入可用之前,此方法将阻塞。如果第一个参数为 null,则读取和丢弃的字节数最多为 len 个。
FilterInputStream 中的 readb - 存储读入数据的缓冲区。off - 目标数组 buf 中的起始偏移量len - 读取的最大字节数。
-1。
IOException - 如果发生 I/O 错误。InputStream.read()
public long skip(long n)
throws IOException
n 个字节的输入。
可能跳过比请求更少的字节数。实际跳过的字节数等于 n 或等于调用 的结果,总之都较小。如果 availablen 为小于零,则不跳过任何字节。
返回实际跳过的字节数。
FilterInputStream 中的 skipn - 要跳过的字节数。
IOException - 如果发生 I/O 错误。
public int available()
throws IOException
InputStream 的 markSupported 方法返回 false。此方法应该由子类重写。
FilterInputStream 中的 availableIOException - 如果发生 I/O 错误。
public void close()
throws IOException
CipherInputStream 的 close 方法调用底层输入流的 close 方法。
Closeable 中的 closeFilterInputStream 中的 closeIOException - 如果发生 I/O 错误。FilterInputStream.inpublic boolean markSupported()
mark 和 reset 方法以及哪一个方法确实不受支持。
FilterInputStream 中的 markSupportedmark 和 reset 方法,所以返回 false。InputStream.mark(int),
InputStream.reset()
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。