Code example for DigestOutputStream

Methods: getMessageDigestwrite

0
     * java.security.DigestOutputStream#write(byte[], int, int) 
     */ 
    public void test_write$BII_5() throws Exception { 
        // Test for method void java.security.DigestOutputStream.write(byte [], 
        // int, int) 
            DigestOutputStream dos = new DigestOutputStream(
                new ByteArrayOutputStream(), MessageDigest.getInstance("SHA"));
            byte digestArray[] = { 23, 43, 44 };
            dos.write(digestArray, 1, 1);
            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));
    } 
 
    /** 
     * java.security.DigestOutputStream#write(int) 
     */ 
Experience pair programming with AI  Get Codota for Java