samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToNew.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:52:25 +0200
changeset 47 f464a16d553a
parent 46 c75861f07646
child 48 c5742322dbc8
permissions -rw-r--r--
Simplified to does not contain the friend API, instead the SPI is directly define by the API
     1 /*
     2  * To change this template, choose Tools | Templates
     3  * and open the template in the editor.
     4  */
     5 
     6 package org.apidesign.impl.security.extension;
     7 
     8 import java.nio.ByteBuffer;
     9 import java.security.MessageDigest;
    10 import java.security.NoSuchAlgorithmException;
    11 import java.util.logging.Level;
    12 import java.util.logging.Logger;
    13 import org.apidesign.spi.security.Digestor;
    14 
    15 /**
    16  *
    17  * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    18  */
    19 // BEGIN: day.end.bridges.BridgeToNew
    20 public class BridgeToNew extends Digestor<MessageDigest> {
    21     @Override
    22     protected MessageDigest create(String algorithm) {
    23         try {
    24             return MessageDigest.getInstance(algorithm);
    25         } catch (NoSuchAlgorithmException ex) {
    26             Logger.getLogger(BridgeToNew.class.getName()).log(Level.FINE, "Cannot find " + algorithm, ex);
    27             return null;
    28         }
    29     }
    30 
    31     @Override
    32     protected byte[] digest(MessageDigest data) {
    33         return data.digest();
    34     }
    35 
    36     @Override
    37     protected void update(MessageDigest data, ByteBuffer input) {
    38         data.update(input);
    39     }
    40 }
    41 // END: day.end.bridges.BridgeToNew