KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > crypto > CipherOutputStream


1 /*
2  * @(#)CipherOutputStream.java 1.6 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7   
8 /*
9  * NOTE:
10  * Because of various external restrictions (i.e. US export
11  * regulations, etc.), the actual source code can not be provided
12  * at this time. This file represents the skeleton of the source
13  * file, so that javadocs of the API can be created.
14  */

15
16 package javax.crypto;
17
18 import java.io.*;
19
20 /**
21  * A CipherOutputStream is composed of an OutputStream and a Cipher so
22  * that write() methods first process the data before writing them out
23  * to the underlying OutputStream. The cipher must be fully
24  * initialized before being used by a CipherOutputStream.
25  *
26  * <p> For example, if the cipher is initialized for encryption, the
27  * CipherOutputStream will attempt to encrypt data before writing out the
28  * encrypted data.
29  *
30  * <p> This class adheres strictly to the semantics, especially the
31  * failure semantics, of its ancestor classes
32  * java.io.OutputStream and java.io.FilterOutputStream. This class
33  * has exactly those methods specified in its ancestor classes, and
34  * overrides them all. Moreover, this class catches all exceptions
35  * that are not thrown by its ancestor classes.
36  *
37  * <p> It is crucial for a programmer using this class not to use
38  * methods that are not defined or overriden in this class (such as a
39  * new method or constructor that is later added to one of the super
40  * classes), because the design and implementation of those methods
41  * are unlikely to have considered security impact with regard to
42  * CipherOutputStream.
43  *
44  * @author Li Gong
45  * @version 1.23, 10/29/03
46  * @see java.io.OutputStream
47  * @see java.io.FilterOutputStream
48  * @see javax.crypto.Cipher
49  * @see javax.crypto.CipherInputStream
50  *
51  * @since 1.4
52  */

53 public class CipherOutputStream extends FilterOutputStream
54 {
55
56     /**
57      * Constructs a CipherOutputStream from an OutputStream and a
58      * Cipher.
59      * <br>Note: if the specified output stream or cipher is
60      * null, a NullPointerException may be thrown later when
61      * they are used.
62      *
63      * @param os the OutputStream object
64      * @param c an initialized Cipher object
65      */

66     public CipherOutputStream(OutputStream os, Cipher c) { }
67
68     /**
69      * Constructs a CipherOutputStream from an OutputStream without
70      * specifying a Cipher. This has the effect of constructing a
71      * CipherOutputStream using a NullCipher.
72      * <br>Note: if the specified output stream is null, a
73      * NullPointerException may be thrown later when it is used.
74      *
75      * @param os the OutputStream object
76      */

77     protected CipherOutputStream(OutputStream os) { }
78
79     /**
80      * Writes the specified byte to this output stream.
81      *
82      * @param b the <code>byte</code>.
83      * @exception IOException if an I/O error occurs.
84      * @since JCE1.2
85      */

86     public void write(int b) throws IOException { }
87
88     /**
89      * Writes <code>b.length</code> bytes from the specified byte array
90      * to this output stream.
91      * <p>
92      * The <code>write</code> method of
93      * <code>CipherOutputStream</code> calls the <code>write</code>
94      * method of three arguments with the three arguments
95      * <code>b</code>, <code>0</code>, and <code>b.length</code>.
96      *
97      * @param b the data.
98      * @exception NullPointerException if <code>b</code> is null.
99      * @exception IOException if an I/O error occurs.
100      * @see javax.crypto.CipherOutputStream#write(byte[], int, int)
101      * @since JCE1.2
102      */

103     public void write(byte[] b) throws IOException { }
104
105     /**
106      * Writes <code>len</code> bytes from the specified byte array
107      * starting at offset <code>off</code> to this output stream.
108      *
109      * @param b the data.
110      * @param off the start offset in the data.
111      * @param len the number of bytes to write.
112      * @exception IOException if an I/O error occurs.
113      * @since JCE1.2
114      */

115     public void write(byte[] b, int off, int len) throws IOException { }
116
117     /**
118      * Flushes this output stream by forcing any buffered output bytes
119      * that have already been processed by the encapsulated cipher object
120      * to be written out.
121      *
122      * <p>Any bytes buffered by the encapsulated cipher
123      * and waiting to be processed by it will not be written out. For example,
124      * if the encapsulated cipher is a block cipher, and the total number of
125      * bytes written using one of the <code>write</code> methods is less than
126      * the cipher's block size, no bytes will be written out.
127      *
128      * @exception IOException if an I/O error occurs.
129      * @since JCE1.2
130      */

131     public void flush() throws IOException { }
132
133     /**
134      * Closes this output stream and releases any system resources
135      * associated with this stream.
136      * <p>
137      * This method invokes the <code>doFinal</code> method of the encapsulated
138      * cipher object, which causes any bytes buffered by the encapsulated
139      * cipher to be processed. The result is written out by calling the
140      * <code>flush</code> method of this output stream.
141      * <p>
142      * This method resets the encapsulated cipher object to its initial state
143      * and calls the <code>close</code> method of the underlying output
144      * stream.
145      *
146      * @exception IOException if an I/O error occurs.
147      * @since JCE1.2
148      */

149     public void close() throws IOException { }
150 }
151
Popular Tags