Dead
[official-gcc.git] / gomp-20050608-branch / libjava / gnu / gcj / io / SimpleSHSStream.java
blobbcf8ea5745082a829807e92f7d90e0be438b5ced
1 // SimpleSHSStream.java
3 /* Copyright (C) 2000 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 package gnu.gcj.io;
12 import java.io.Serializable;
13 import java.io.*;
14 import java.lang.reflect.*;
16 public class SimpleSHSStream extends java.io.DataOutputStream
18 int counter;
20 final int SHS_BLOCKSIZE = 64;
21 final int SHS_DIGESTSIZE = 20;
23 byte buf[];
24 byte shs_info[];
26 native static byte [] shsFinal (byte info[]);
27 native static void shsUpdate (byte info[], byte buf[], int count);
28 native static byte [] shsInit ();
30 private void update (byte b)
32 buf [counter++] = b;
33 if (counter % SHS_BLOCKSIZE == 0)
35 counter = 0;
36 shsUpdate (shs_info, buf, SHS_BLOCKSIZE);
40 public void write (int b) throws IOException
42 update ((byte)b);
43 super.write (b);
46 public void write (byte[] b, int off, int len) throws IOException
48 for (int i = 0; i < len; i++)
49 write (b[i+off]);
52 public byte[] digest()
54 shsUpdate (shs_info, buf, counter);
55 return shsFinal (shs_info);
58 public SimpleSHSStream (OutputStream out)
60 super (out);
61 buf = new byte[SHS_BLOCKSIZE];
62 shs_info = shsInit ();
63 counter = 0;