Example usage for com.google.common.hash HashingOutputStream write

List of usage examples for com.google.common.hash HashingOutputStream write

Introduction

In this page you can find the example usage for com.google.common.hash HashingOutputStream write.

Prototype

@Override
    public void write(int b) throws IOException 

Source Link

Usage

From source file:io.macgyver.plugin.cmdb.AppInstanceManager.java

public String computeSignature(ObjectNode n, Set<String> exclusions) {
    List<String> list = Lists.newArrayList(n.fieldNames());
    Collections.sort(list);/* www. j  av a2s . c o  m*/

    HashingOutputStream hos = new HashingOutputStream(Hashing.sha1(), ByteStreams.nullOutputStream());

    list.forEach(it -> {

        if (exclusions != null && !exclusions.contains(it)) {
            JsonNode val = n.get(it);
            if (val.isObject() || val.isArray()) {
                // skipping
            } else {
                try {
                    hos.write(it.getBytes());
                    hos.write(val.toString().getBytes());
                } catch (IOException e) {
                }
            }
        }
    });

    return hos.hash().toString();

}