/[classpath]/classpath/java/security/DigestOutputStream.java
ViewVC logotype

Diff of /classpath/java/security/DigestOutputStream.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by cbj, Mon Mar 25 05:12:19 2002 UTC revision 1.6 by mkoch, Thu Oct 21 20:22:12 2004 UTC
# Line 1  Line 1 
1  /* DigestOutputStream.java --- An output stream tied to a message digest  /* DigestOutputStream.java --- An output stream tied to a message digest
2     Copyright (C) 1999 Free Software Foundation, Inc.     Copyright (C) 1999, 2004  Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 35  this exception to your version of the li Line 35  this exception to your version of the li
35  obligated to do so.  If you do not wish to do so, delete this  obligated to do so.  If you do not wish to do so, delete this
36  exception statement from your version. */  exception statement from your version. */
37    
38    
39  package java.security;  package java.security;
40    
 import java.io.OutputStream;  
41  import java.io.FilterOutputStream;  import java.io.FilterOutputStream;
42  import java.io.IOException;  import java.io.IOException;
43    import java.io.OutputStream;
44    
45  /**  /**
46     DigestOutputStream is a class that ties an OutputStream with a   * DigestOutputStream is a class that ties an OutputStream with a
47     MessageDigest. The Message Digest is used by the class to update it   * MessageDigest. The Message Digest is used by the class to update it
48     self as bytes are written to the OutputStream.   * self as bytes are written to the OutputStream.
49     *
50     The updating to the digest depends on the on flag which is set to   * The updating to the digest depends on the on flag which is set to
51     true by default that tells the class to update the data in the   * true by default that tells the class to update the data in the
52     message digest.   * message digest.
53     *
54     @version 0.0   * @version 0.0
55     @author Mark Benvenuto <ivymccough@worldnet.att.net>   * @author Mark Benvenuto <ivymccough@worldnet.att.net>
56   */   */
57  public class DigestOutputStream extends FilterOutputStream  public class DigestOutputStream extends FilterOutputStream
58  {  {
59    /**    /**
60       The message digest for the DigestOutputStream     * The message digest for the DigestOutputStream
61     */     */
62    protected MessageDigest digest;    protected MessageDigest digest;
63    
# Line 64  public class DigestOutputStream extends Line 65  public class DigestOutputStream extends
65    private boolean state = true;    private boolean state = true;
66    
67    /**    /**
68       Constructs a new DigestOutputStream.  It associates a     * Constructs a new DigestOutputStream.  It associates a
69       MessageDigest with the stream to compute the stream as data is     * MessageDigest with the stream to compute the stream as data is
70       written.     * written.
71       *
72       @param stream An OutputStream to associate this stream with     * @param stream An OutputStream to associate this stream with
73       @param digest A MessageDigest to hash the stream with     * @param digest A MessageDigest to hash the stream with
74     */     */
75    public DigestOutputStream(OutputStream stream, MessageDigest digest)    public DigestOutputStream(OutputStream stream, MessageDigest digest)
76    {    {
# Line 78  public class DigestOutputStream extends Line 79  public class DigestOutputStream extends
79    }    }
80    
81    /**    /**
82       Returns the MessageDigest associated with this DigestOutputStream     * Returns the MessageDigest associated with this DigestOutputStream
83       *
84       @return The MessageDigest used to hash this stream     * @return The MessageDigest used to hash this stream
85     */     */
86    public MessageDigest getMessageDigest()    public MessageDigest getMessageDigest()
87    {    {
# Line 88  public class DigestOutputStream extends Line 89  public class DigestOutputStream extends
89    }    }
90    
91    /**    /**
92       Sets the current MessageDigest to current parameter     * Sets the current MessageDigest to current parameter
93       *
94       @param digest A MessageDigest to associate with this stream     * @param digest A MessageDigest to associate with this stream
95     */     */
96    public void setMessageDigest(MessageDigest digest)    public void setMessageDigest(MessageDigest digest)
97    {    {
# Line 99  public class DigestOutputStream extends Line 100  public class DigestOutputStream extends
100    
101    
102    /**    /**
103       Updates the hash if the on flag is true and then writes a byte to     * Updates the hash if the on flag is true and then writes a byte to
104       the underlying output stream.     * the underlying output stream.
105       *
106       @param b A byte to write to the output stream     * @param b A byte to write to the output stream
107       *
108       @exception IOException if the underlying output stream     * @exception IOException if the underlying output stream
109       cannot write the byte, this is thrown.     * cannot write the byte, this is thrown.
110     */     */
111    public void write(int b) throws IOException    public void write(int b) throws IOException
112    {    {
# Line 116  public class DigestOutputStream extends Line 117  public class DigestOutputStream extends
117    }    }
118    
119    /**    /**
120       Updates the hash if the on flag is true and then writes the bytes     * Updates the hash if the on flag is true and then writes the bytes
121       to the underlying output stream.     * to the underlying output stream.
122       *
123       @param b Bytes to write to the output stream     * @param b Bytes to write to the output stream
124       @param off Offset to start to start at in array     * @param off Offset to start to start at in array
125       @param len Length of data to write     * @param len Length of data to write
126       *
127       @exception IOException if the underlying output stream     * @exception IOException if the underlying output stream
128       cannot write the bytes, this is thrown.     * cannot write the bytes, this is thrown.
129     */     */
130    public void write(byte[]b, int off, int len) throws IOException    public void write(byte[]b, int off, int len) throws IOException
131    {    {
# Line 135  public class DigestOutputStream extends Line 136  public class DigestOutputStream extends
136    }    }
137    
138    /**    /**
139       Sets the flag specifying if this DigestOutputStream updates the     * Sets the flag specifying if this DigestOutputStream updates the
140       digest in the write() methods. The default is on;     * digest in the write() methods. The default is on;
141       *
142       @param on True means it digests stream, false means it does not     * @param on True means it digests stream, false means it does not
143     */     */
144    public void on(boolean on)    public void on(boolean on)
145    {    {
# Line 146  public class DigestOutputStream extends Line 147  public class DigestOutputStream extends
147    }    }
148    
149    /**    /**
150       Converts the output stream and underlying message digest to a string.     * Converts the output stream and underlying message digest to a string.
151       *
152       @return A string representing the output stream and message digest.     * @return A string representing the output stream and message digest.
153     */     */
154    public String toString()    public String toString()
155    {    {

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26