1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 1999-2008 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 * 20 */ 21 package com.sun.org.apache.xml.internal.security.utils; 22 23 import java.io.ByteArrayOutputStream; 24 25 import com.sun.org.apache.xml.internal.security.algorithms.MessageDigestAlgorithm; 26 27 /** 28 * @author raul 29 * 30 */ 31 public class DigesterOutputStream extends ByteArrayOutputStream { 32 final MessageDigestAlgorithm mda; 33 static java.util.logging.Logger log = 34 java.util.logging.Logger.getLogger 35 (DigesterOutputStream.class.getName()); 36 37 /** 38 * @param mda 39 */ 40 public DigesterOutputStream(MessageDigestAlgorithm mda) { 41 this.mda=mda; 42 } 43 44 /** @inheritDoc */ 45 public void write(byte[] arg0) { 46 write(arg0, 0, arg0.length); 47 } 48 49 /** @inheritDoc */ 50 public void write(int arg0) { 51 mda.update((byte)arg0); 52 } 53 54 /** @inheritDoc */ 55 public void write(byte[] arg0, int arg1, int arg2) { 56 if (log.isLoggable(java.util.logging.Level.FINE)) { 57 log.log(java.util.logging.Level.FINE, "Pre-digested input:"); 58 StringBuffer sb = new StringBuffer(arg2); 59 for (int i=arg1; i<(arg1+arg2); i++) { 60 sb.append((char) arg0[i]); 61 } 62 log.log(java.util.logging.Level.FINE, sb.toString()); 63 } 64 mda.update(arg0, arg1, arg2); 65 } 66 67 /** 68 * @return the digest value 69 */ 70 public byte[] getDigestValue() { 71 return mda.digest(); 72 } 73 }