KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xml > internal > security > utils > DigesterOutputStream


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package com.sun.org.apache.xml.internal.security.utils;
18
19 import java.io.ByteArrayOutputStream JavaDoc;
20
21 import com.sun.org.apache.xml.internal.security.algorithms.MessageDigestAlgorithm;
22
23 /**
24  * @author raul
25  *
26  */

27 public class DigesterOutputStream extends ByteArrayOutputStream JavaDoc {
28     final static byte none[]="error".getBytes();
29     final MessageDigestAlgorithm mda;
30     /**
31      * @param mda
32      */

33     public DigesterOutputStream(MessageDigestAlgorithm mda) {
34         this.mda=mda;
35     }
36
37     /** @inheritDoc */
38     public byte[] toByteArray() {
39         return none;
40     }
41     
42     /** @inheritDoc */
43     public void write(byte[] arg0) {
44         mda.update(arg0);
45     }
46     
47     /** @inheritDoc */
48     public void write(int arg0) {
49         mda.update((byte)arg0);
50     }
51     
52     /** @inheritDoc */
53     public void write(byte[] arg0, int arg1, int arg2) {
54         mda.update(arg0, arg1, arg2);
55     }
56     
57     /**
58      * @return the digest value
59      */

60     public byte[] getDigestValue() {
61          return mda.digest();
62     }
63 }
64
Popular Tags