samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToNew.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/messagedigest/src-bridge/org/apidesign/impl/security/extension/BridgeToNew.java Sat Jun 14 09:52:23 2008 +0200
1.3 @@ -0,0 +1,44 @@
1.4 +/*
1.5 + * To change this template, choose Tools | Templates
1.6 + * and open the template in the editor.
1.7 + */
1.8 +
1.9 +package org.apidesign.impl.security.extension;
1.10 +
1.11 +import org.apidesign.impl.security.friendapi.DigestImplementation;
1.12 +import org.apidesign.impl.security.friendapi.DigestProvider;
1.13 +import java.nio.ByteBuffer;
1.14 +import java.security.MessageDigest;
1.15 +import java.security.NoSuchAlgorithmException;
1.16 +import java.util.logging.Level;
1.17 +import java.util.logging.Logger;
1.18 +
1.19 +/**
1.20 + *
1.21 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.22 + */
1.23 +// BEGIN: day.end.bridges.BridgeToNew
1.24 +public class BridgeToNew implements DigestProvider {
1.25 +
1.26 + public DigestImplementation create(String algorithm) {
1.27 + try {
1.28 + final MessageDigest md = MessageDigest.getInstance(algorithm);
1.29 + return new DigestImplementation(algorithm) {
1.30 +
1.31 + @Override
1.32 + public void update(ByteBuffer bb) {
1.33 + md.update(bb);
1.34 + }
1.35 +
1.36 + @Override
1.37 + public byte[] digest() {
1.38 + return md.digest();
1.39 + }
1.40 + };
1.41 + } catch (NoSuchAlgorithmException ex) {
1.42 + Logger.getLogger(BridgeToNew.class.getName()).log(Level.INFO, null, ex);
1.43 + return null;
1.44 + }
1.45 + }
1.46 +}
1.47 +// END: day.end.bridges.BridgeToNew