samples/messagedigest/src-test/test/CountingDigestor.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:56:12 +0200
changeset 132 3bc4c54f4bcc
parent 51 130e099942d8
child 153 b5cbb797ec0a
permissions -rw-r--r--
Truncating all examples to 80 characters per line
     1 /*
     2  * To change this template, choose Tools | Templates
     3  * and open the template in the editor.
     4  */
     5 
     6 package test;
     7 
     8 import java.nio.ByteBuffer;
     9 import org.apidesign.spi.security.Digestor;
    10 
    11 /**
    12  *
    13  * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    14  */
    15 // BEGIN: day.end.bridges.CountingDigestor
    16 public final class CountingDigestor extends Digestor<int[]> {
    17     @Override
    18     protected byte[] digest(int[] data) {
    19         int i = data[0];
    20         byte[] arr = { 
    21             (byte) (i & 255), 
    22             (byte) ((i >> 8) & 255), 
    23             (byte) ((i >> 16) & 255), 
    24             (byte) ((i >> 24) & 255) 
    25         };
    26         return arr;
    27     }
    28 
    29     @Override
    30     protected int[] create(String algorithm) {
    31         return "cnt".equals(algorithm) ? new int[1] : null; // NOI18N
    32     }
    33 
    34     @Override
    35     protected void update(int[] data, ByteBuffer input) {
    36         data[0] += input.remaining();
    37         input.position(input.position() + input.remaining());
    38     }
    39 }
    40 // END: day.end.bridges.CountingDigestor