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