Code example for DigestOutputStream

Methods: getMessageDigest, write

0
        method = "on", 
        args = {boolean.class} 
    ) 
    public final void testOn() throws IOException { 
        for (int k=0; k<algorithmName.length; k++) {
            try { 
                ByteArrayOutputStream bos = new ByteArrayOutputStream(MY_MESSAGE_LEN);
                MessageDigest md = MessageDigest.getInstance(algorithmName[k]);
                DigestOutputStream dos = new DigestOutputStream(bos, md);
                 
                // turn digest off 
                dos.on(false);
                 
                for (int i=0; i<MY_MESSAGE_LEN-1; i++) {
                    dos.write(myMessage[i]);
                } 
                 
                // turn digest on 
                dos.on(true);
                 
                // read remaining byte