public class CipherOutputStream extends FilterOutputStream
例如,如果将密码初始化为加密,CipherOutputStream会在写出加密数据之前尝试加密数据。
该类严格遵守其祖先类java.io.OutputStream和java.io.FilterOutputStream的语义,特别是失败语义。 这个类只有在其祖先类中指定的方法,并覆盖它们全部。 此外,此类捕获其祖先类不抛出的所有异常。
对于使用此类的程序员,不要使用在此类中未定义或覆盖的方法(例如后来添加到其中一个超类的新方法或构造函数),因为这些方法的设计和实现不太可能考虑到对CipherOutputStream的安全影响。
OutputStream , FilterOutputStream , Cipher , CipherInputStream
out| Modifier | Constructor and Description |
|---|---|
protected |
CipherOutputStream(OutputStream os)
在不指定密码的情况下,从OutputStream构造CipherOutputStream。
|
|
CipherOutputStream(OutputStream os, Cipher c)
从OutputStream和Cipher构造一个CipherOutputStream。
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
关闭此输出流并释放与此流相关联的任何系统资源。
|
void |
flush()
通过强制已经由封装的密码对象处理的任何缓冲的输出字节被写出来刷新输出流。
|
void |
write(byte[] b)
将
b.length字节从指定的字节数组写入此输出流。
|
void |
write(byte[] b, int off, int len)
从指定的字节数组写入
len个字节,从偏移
off开始输出到此输出流。
|
void |
write(int b)
将指定的字节写入此输出流。
|
public CipherOutputStream(OutputStream os, Cipher c)
os - OutputStream对象
c - 一个初始化的Cipher对象
protected CipherOutputStream(OutputStream os)
os - OutputStream对象
public void write(int b)
throws IOException
write在
FilterOutputStream
b -
byte 。
IOException - 如果发生I / O错误。
public void write(byte[] b)
throws IOException
b.length字节从指定的字节数组写入此输出流。
该write的方法CipherOutputStream调用write的三个参数与三个参数的方法b , 0和b.length 。
write在
FilterOutputStream
b - 数据。
NullPointerException - 如果
b为空。
IOException - 如果发生I / O错误。
write(byte[], int, int)
public void write(byte[] b,
int off,
int len)
throws IOException
len个字节,从偏移
off开始输出到此输出流。
write在
FilterOutputStream
b - 数据。
off - 数据中的起始偏移量。
len - 要写入的字节数。
IOException - 如果发生I / O错误。
FilterOutputStream.write(int)
public void flush()
throws IOException
由封装密码缓冲并等待被其处理的任何字节将不会被写出。 例如,如果封装的密码是块密码,并且使用write方法之一写入的总字节数小于密码的块大小,则不会写出任何字节。
flush在接口
Flushable
flush在类别
FilterOutputStream
IOException - 如果发生I / O错误。
FilterOutputStream.out
public void close()
throws IOException
此方法调用封装密码对象的doFinal方法,这将导致处理由封装密码缓冲的任何字节。 结果是通过调用此输出流的flush方法来写出来的。
该方法将封装的密码对象重置为初始状态,并调用底层输出流的close方法。
close在接口
Closeable
close在界面
AutoCloseable
close在
FilterOutputStream
IOException - 如果发生I / O错误。
FilterOutputStream.flush(),
FilterOutputStream.out
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.