diff -r f464a16d553a -r dbe255defdbb samples/messagedigest/src-new-api/org/apidesign/api/security/DigestImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/messagedigest/src-new-api/org/apidesign/api/security/DigestImpl.java Thu Dec 25 19:25:59 2008 +0100 @@ -0,0 +1,46 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.apidesign.api.security; + +import java.nio.ByteBuffer; +import org.apidesign.spi.security.Digestor; + +/** + * + * @author Jaroslav Tulach + */ +// BEGIN: day.end.bridges.DigestImpl +final class DigestImpl { + private static final DigestorAccessorImpl ACCESSOR = new DigestorAccessorImpl(); + + private final Digestor digestor; + private final String algorithm; + private Data data; + + private DigestImpl(Digestor digestor, String algorithm, Data d) { + this.digestor = digestor; + this.algorithm = algorithm; + this.data = d; + } + + static DigestImpl create(Digestor digestor, String algorithm) { + // indirectly calls digestor.create(algorithm) + Data d = ACCESSOR.create(digestor, algorithm); + if (d == null) { + return null; + } else { + return new DigestImpl(digestor, algorithm, d); + } + } + + byte[] digest(ByteBuffer bb) { + // indirectly calls digestor.update(data, bb) + ACCESSOR.update(digestor, data, bb); + // indirectly calls digestor.digest(data) + return ACCESSOR.digest(digestor, data); + } +} +// END: day.end.bridges.DigestImpl \ No newline at end of file