Example usage for com.google.common.hash Hashing crc32

List of usage examples for com.google.common.hash Hashing crc32

Introduction

In this page you can find the example usage for com.google.common.hash Hashing crc32.

Prototype

public static HashFunction crc32() 

Source Link

Document

Returns a hash function implementing the CRC-32 checksum algorithm (32 hash bits) by delegating to the CRC32 Checksum .

Usage

From source file:com.lithium.flow.util.HashFunctions.java

@Nonnull
public static HashFunction of(@Nonnull String name) {
    checkNotNull(name);//  w ww . j a v  a 2 s.  co m
    switch (name) {
    case "adler32":
        return Hashing.adler32();
    case "crc32":
        return Hashing.crc32();
    case "md5":
        return Hashing.md5();
    case "sha1":
        return Hashing.sha1();
    case "sha256":
        return Hashing.sha256();
    case "sha512":
        return Hashing.sha512();
    case "sipHash24":
        return Hashing.sipHash24();
    case "murmur3_32":
        return Hashing.murmur3_32();
    case "murmur3_128":
        return Hashing.murmur3_128();
    default:
        throw new RuntimeException("unknown hash: " + name);
    }
}

From source file:org.thingsboard.server.utils.MiscUtils.java

public static HashFunction forName(String name) {
    switch (name) {
    case "murmur3_32":
        return Hashing.murmur3_32();
    case "murmur3_128":
        return Hashing.murmur3_128();
    case "crc32":
        return Hashing.crc32();
    case "md5":
        return Hashing.md5();
    default:/* w  w w .j  a  va2s . co  m*/
        throw new IllegalArgumentException("Can't find hash function with name " + name);
    }
}

From source file:org.graylog.plugins.pipelineprocessor.functions.hashing.CRC32.java

@Override
protected String getDigest(String value) {
    return Hashing.crc32().hashString(value, StandardCharsets.UTF_8).toString();
}

From source file:playacem.allrondism.core.util.ComparableMergableImage.java

public ComparableMergableImage(File path, String background, String overlay) {

    this.path = path;
    this.bg = background;
    this.overlay = overlay;

    img = new File(path, bg + ".png");
    overlayFile = new File(path, this.overlay + ".png");

    try {/*  w  ww.j a  va2 s  .  c o m*/
        this.setHashBG(Files.hash(img, Hashing.crc32()));
    } catch (IOException e) {
        LogHelper.alert(getErrorText("hashing the background file"));
        LogHelper.alert(img.getAbsolutePath());
    }

    try {
        this.setHashOverlay(Files.hash(overlayFile, Hashing.crc32()));
    } catch (IOException e) {
        LogHelper.alert(getErrorText("hashing the overlay file"));
        LogHelper.alert(overlayFile.getAbsolutePath());

    }

}

From source file:ome.util.checksum.CRC32ChecksumProviderImpl.java

protected CRC32ChecksumProviderImpl() {
    super(Hashing.crc32());
}

From source file:com.intellij.ide.plugins.RepositoryHelper.java

public static List<IdeaPluginDescriptor> loadPluginsFromRepository(@Nullable ProgressIndicator indicator)
        throws Exception {
    ApplicationInfoEx appInfo = ApplicationInfoImpl.getShadowInstance();

    String url = appInfo.getPluginsListUrl() + "?build=" + appInfo.getBuild().asString();

    if (indicator != null) {
        indicator.setText2(//w  ww  .  jav  a2 s  .c  o m
                IdeBundle.message("progress.connecting.to.plugin.manager", appInfo.getPluginManagerUrl()));
    }

    File pluginListFile = new File(PathManager.getPluginsPath(), PLUGIN_LIST_FILE);
    if (pluginListFile.length() > 0) {
        try {
            url = url + "&crc32=" + Files.hash(pluginListFile, Hashing.crc32()).toString();
        } catch (NoSuchMethodError e) {
            String guavaPath = PathUtil.getJarPathForClass(Hashing.class);
            throw new RuntimeException(guavaPath, e);
        }
    }

    HttpURLConnection connection = HttpConfigurable.getInstance().openHttpConnection(url);
    connection.setRequestProperty("Accept-Encoding", "gzip");

    if (indicator != null) {
        indicator.setText2(IdeBundle.message("progress.waiting.for.reply.from.plugin.manager",
                appInfo.getPluginManagerUrl()));
    }

    connection.connect();
    try {
        if (indicator != null) {
            indicator.checkCanceled();
        }

        if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
            return loadPluginList(pluginListFile);
        }

        String encoding = connection.getContentEncoding();
        InputStream is = connection.getInputStream();
        try {
            if ("gzip".equalsIgnoreCase(encoding)) {
                is = new GZIPInputStream(is);
            }

            if (indicator != null) {
                indicator.setText2(IdeBundle.message("progress.downloading.list.of.plugins"));
            }

            return readPluginsStream(is, indicator, PLUGIN_LIST_FILE);
        } finally {
            is.close();
        }
    } finally {
        connection.disconnect();
    }
}

From source file:ph.samson.maven.enforcer.rule.checksum.FileChecksum.java

@Override
public void execute(EnforcerRuleHelper erh) throws EnforcerRuleException {
    if (file == null || !file.canRead()) {
        throw new EnforcerRuleException("Missing file: " + file);
    }//ww w  .java  2  s. co  m

    HashFunction hashFn;
    switch (type) {
    case "crc32":
        hashFn = Hashing.crc32();
        break;
    case "crc32c":
        hashFn = Hashing.crc32c();
        break;
    case "md5":
        hashFn = Hashing.md5();
        break;
    case "sha1":
        hashFn = Hashing.sha1();
        break;
    case "sha256":
        hashFn = Hashing.sha256();
        break;
    case "sha512":
        hashFn = Hashing.sha512();
        break;
    default:
        throw new EnforcerRuleException("Unsupported hash type: " + type);
    }

    String hash;
    try {
        hash = hashFn.hashBytes(Files.readAllBytes(file.toPath())).toString();
    } catch (IOException ex) {
        throw new EnforcerRuleException("Failed reading " + file, ex);
    }

    if (!hash.equalsIgnoreCase(checksum)) {
        throw new EnforcerRuleException(
                type + " hash of " + file + " was " + hash + " but expected " + checksum);
    }
}

From source file:com.ziduye.utils.security.Digests.java

public static int crc32(byte[] input) {
    return Hashing.crc32().hashBytes(input).asInt();
}

From source file:com.ziduye.utils.security.Digests.java

public static int crc32(String input) {
    return Hashing.crc32().hashString(input, UTF8).asInt();
}

From source file:org.etourdot.vertx.mods.XmlXPathHandler.java

public void handle(Message message) {
    final JsonObject messageBody = (JsonObject) message.body();
    final String xpath = messageBody.getString(XPATH);
    final String xml = messageBody.getString(XML);
    final String url_xml = messageBody.getString(URL_XML);
    //final JsonArray params = messageBody.getArray(PARAMS);

    if (Strings.isNullOrEmpty(xml) && Strings.isNullOrEmpty(url_xml)) {
        sendError(message, "xml ou url_xml must be specified");
        return;/*from  w ww. ja  va  2  s .c  o m*/
    }
    if (Strings.isNullOrEmpty(xpath)) {
        sendError(message, "xpath must be specified");
        return;
    }

    try {
        final Source xml_source;
        if (!Strings.isNullOrEmpty(xml)) {
            if (!Strings.isNullOrEmpty(url_xml)) {
                sendError(message, "xml either url_xml must be specified");
                return;
            }
            xml_source = new StreamSource(new ByteArrayInputStream(xml.getBytes("UTF-8")));
        } else {
            xml_source = new SAXSource(new InputSource(url_xml));
        }
        final HashCode key = Hashing.crc32().hashString(xpath, Charsets.UTF_8);
        final XPathSelector xPathSelector = cacheXPathSelector.get(key, new Callable<XPathSelector>() {
            @Override
            public XPathSelector call() throws Exception {
                final XPathCompiler xPathCompiler = processor.newXPathCompiler();
                final XPathExecutable xPathExecutable = xPathCompiler.compile(xpath);
                return xPathExecutable.load();
            }
        });
        final XdmNode source = processor.newDocumentBuilder().build(xml_source);
        xPathSelector.setContextItem(source);
        final XdmValue xdmValue = xPathSelector.evaluate();
        final StringWriter writer = new StringWriter();
        final Serializer out = processor.newSerializer(writer);
        out.serializeXdmValue(xdmValue);
        JsonObject outputObject = new JsonObject();
        outputObject.putString("output", writer.toString());
        sendOK(message, outputObject);
    } catch (SaxonApiException | UnsupportedEncodingException | ExecutionException e) {
        sendError(message, e.getMessage());
    }
}