| author | Jaroslav Tulach <jtulach@netbeans.org> |
| Sat Feb 20 18:20:10 2010 +0100 | |
| changeset 347 | 481fbbbcc7b7 |
| parent 154 | 0fd5e9c500b9 |
| 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@51 | 13 |
* @author Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
| jtulach@44 | 14 |
*/ |
| jtulach@51 | 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@154 | 20 |
byte[] arr = {
|
| jtulach@154 | 21 |
(byte) (i & 255), |
| jtulach@154 | 22 |
(byte) ((i >> 8) & 255), |
| jtulach@154 | 23 |
(byte) ((i >> 16) & 255), |
| jtulach@154 | 24 |
(byte) ((i >> 24) & 255) |
| jtulach@154 | 25 |
}; |
| jtulach@44 | 26 |
return arr; |
| jtulach@44 | 27 |
} |
| jtulach@44 | 28 |
|
| jtulach@44 | 29 |
@Override |
| jtulach@44 | 30 |
protected int[] create(String algorithm) {
|
| jtulach@211 | 31 |
return "cnt".equals(algorithm) ? new int[1] : null; |
| jtulach@44 | 32 |
} |
| jtulach@44 | 33 |
|
| jtulach@44 | 34 |
@Override |
| jtulach@44 | 35 |
protected void update(int[] data, ByteBuffer input) {
|
| jtulach@44 | 36 |
data[0] += input.remaining(); |
| jtulach@44 | 37 |
input.position(input.position() + input.remaining()); |
| jtulach@44 | 38 |
} |
| jtulach@44 | 39 |
} |
| jtulach@51 | 40 |
// END: day.end.bridges.CountingDigestor |