Code example for DigestOutputStream

Methods: getMessageDigestwrite

0
    /** 
     * java.security.DigestOutputStream#write(int) 
     */ 
    public void test_writeI() throws Exception { 
        // Test for method void java.security.DigestOutputStream.write(int) 
            DigestOutputStream dos = new DigestOutputStream(
                new ByteArrayOutputStream(), MessageDigest.getInstance("SHA"));
            dos.write((byte) 43);
            byte digestResult[] = dos.getMessageDigest().digest();
            byte expected[] = { -87, 121, -17, 16, -52, 111, 106, 54, -33, 107,
                    -118, 50, 51, 7, -18, 59, -78, -30, -37, -100 }; 
 
            assertTrue("Digest did not return expected result.",
                       Arrays.equals(digestResult, expected));
    } 
 
 
    private class MyOutputStream extends OutputStream {
        @Override 
        public void write(int arg0) throws IOException {
Stop searching for code, let great code find you!  Add Codota to your java IDE