Code example for MessageDigest

Methods: update

0
    private static int writePingPayload(OutputStream ping,
                                        MessageDigest checksum,
                                        String payload) throws IOException {
 
        byte [] data = payload.getBytes(PING_CHARSET);
        checksum.update(data);
 
        data = JSONObject.quote(payload).getBytes(PING_CHARSET);
        // first and last bytes are quotes inserted by JSONObject.quote; discard them 
        ping.write(data, 1, data.length - 2);
        return data.length - 2;
    } 
 
    private static void fillPingHeader(OutputStream ping, MessageDigest checksum, String slug)
            throws IOException { 
 
        // ping file header 
        byte [] data = ("{" +
            "\"slug\":" + JSONObject.quote(slug) + "," +
            "\"payload\":\"").getBytes(PING_CHARSET);
        ping.write(data);