Example usage for org.apache.commons.codec.digest DigestUtils md5Hex

List of usage examples for org.apache.commons.codec.digest DigestUtils md5Hex

Introduction

In this page you can find the example usage for org.apache.commons.codec.digest DigestUtils md5Hex.

Prototype

public static String md5Hex(String data) 

Source Link

Usage

From source file:com.magnet.mmx.server.plugin.mmxmgmt.push.PushIdGeneratorImpl.java

@Override
public String generateId(String appId, String deviceId) {
    StringBuilder builder = new StringBuilder();
    builder.append(Long.toString(getCurrentTimeMillis()));
    builder.append(appId);//w  w w . j  a  va2 s.  co m
    builder.append(deviceId);
    builder.append(randomGenerator.nextLong());
    String generated;
    try {
        byte[] bytes = builder.toString().getBytes(MMXServerConstants.UTF8_ENCODING);
        generated = DigestUtils.md5Hex(bytes);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException(e);
    }
    return generated;
}

From source file:com.glaf.core.jdbc.connection.ConnectionProviderFactory.java

protected static void closeAndCreate(Properties properties) {
    String jdbcUrl = properties.getProperty(DBConfiguration.JDBC_URL);
    String cacheKey = DigestUtils.md5Hex(jdbcUrl);
    ConnectionProvider provider = null;// ww  w  .j a  v  a2 s  .  c o m
    if (providerCache.get(cacheKey) != null) {
        provider = providerCache.get(cacheKey);
        provider.close();
    }
    provider = createProvider(properties, null);
    providerCache.put(cacheKey, provider);
}

From source file:mupomat.controller.ObradaOperater.java

@Override
public void promjeniPostojeci(Operater entitet) {
    try {//from   w ww .ja va2 s.  c  o  m
        Connection veza = MySqlBazaPodataka.getConnection();
        PreparedStatement izraz = null;
        if (entitet.getLozinka().length() > 0) {
            izraz = veza
                    .prepareStatement("update operater set lozinka=?,ime=?,prezime=?,aktivan=? where sifra=? ");

            izraz.setString(1, DigestUtils.md5Hex(entitet.getLozinka()));
            izraz.setString(2, entitet.getIme());
            izraz.setString(3, entitet.getPrezime());
            izraz.setBoolean(4, entitet.isAktivan());
            izraz.setInt(5, entitet.getSifra());
            izraz.executeUpdate();
        } else {
            izraz = veza.prepareStatement("update operater set  ime=?,prezime=?,aktivan=? where sifra=? ");

            izraz.setString(1, entitet.getIme());
            izraz.setString(2, entitet.getPrezime());
            izraz.setBoolean(3, entitet.isAktivan());
            izraz.setInt(4, entitet.getSifra());
            izraz.executeUpdate();
        }
        izraz.close();
        veza.close();
    } catch (Exception e) {
        //  System.out.println(e.getMessage());
        e.printStackTrace();
        return;
    }
}

From source file:de.betterform.connector.serializer.FormDataSerializer.java

/**
 * Serialize instance into multipart/form-data stream as defined in
 * http://www.w3.org/TR/xforms/slice11.html#serialize-form-data
 *
 * @param submission/*from   w  w  w . java 2 s . c o  m*/
 * @param instance
 * @param wrapper
 * @param defaultEncoding
 * @throws Exception on error
 */
public void serialize(Submission submission, Node instance, SerializerRequestWrapper wrapper,
        String defaultEncoding) throws Exception {
    // sanity checks
    if (instance == null) {
        return;
    }

    switch (instance.getNodeType()) {

    case Node.ELEMENT_NODE:
    case Node.TEXT_NODE:
        break;

    case Node.DOCUMENT_NODE:
        instance = ((Document) instance).getDocumentElement();
        break;

    default:
        return;
    }

    String encoding = defaultEncoding;
    if (submission.getEncoding() != null) {
        encoding = submission.getEncoding();
    }

    // generate boundary
    Random rnd = new Random(System.currentTimeMillis());
    String boundary = DigestUtils.md5Hex(getClass().getName() + rnd.nextLong());

    // serialize the instance
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(bos, encoding)));
    if (instance.getNodeType() == Node.ELEMENT_NODE) {
        serializeElement(writer, (Element) instance, boundary, encoding);
    } else {
        writer.print(instance.getTextContent());
    }
    writer.print("\r\n--" + boundary + "--");
    writer.flush();
    bos.writeTo(wrapper.getBodyStream());
    wrapper.addHeader("internal-boundary-mark", boundary);
}

From source file:com.github.swt_release_fetcher.Artifact.java

private boolean validateFileMd5(File file, String expected) throws IOException {
    InputStream downloadedFile = new FileInputStream(file);
    try {/*from w  w  w.  j  a  va2 s .c o  m*/
        String calculatedMd5 = DigestUtils.md5Hex(downloadedFile);
        return calculatedMd5.equals(expected);
    } finally {
        downloadedFile.close();
    }
}

From source file:com.googlecode.fascinator.common.storage.StorageUtils.java

/**
 * Hash the internal contents of a file.
 * /*from   w  ww .  ja  v a 2 s .c o  m*/
 * @param file The File to hash
 * @return String Hash of the file's contents
 * @throws IOException If there was an error accessing the file
 */
private static String hashFile(File file) throws IOException {
    return DigestUtils.md5Hex(FileUtils.readFileToString(file));
}

From source file:edu.lternet.pasta.doi.DigitalObjectIdentifier.java

/**
 * Return a new Digital Object Identifier object for the given PASTA
 * identifier.//  www .  j av a2  s  .  com
 *
 * @param pastaId The PASTA identifier
 * @throws ConfigurationException
 */
public DigitalObjectIdentifier(String pastaId) throws ConfigurationException {

    Options options = ConfigurationListener.getOptions();

    if (options == null) {
        ConfigurationListener configurationListener = new ConfigurationListener();
        configurationListener.initialize(dirPath);
        options = ConfigurationListener.getOptions();
    }

    loadOptions(options);

    this.pastaId = pastaId;
    md5Id = DigestUtils.md5Hex(pastaId);

}

From source file:com.thoughtworks.go.domain.DirHandlerTest.java

@Test
public void shouldComputeMd5ForEveryFileInADirectory() throws IOException {
    zip = createZip("under_dir");
    dirHandler.useArtifactMd5Checksums(checksums);

    when(checksums.md5For("fetch_dest/first")).thenReturn(DigestUtils.md5Hex("First File"));
    when(checksums.md5For("fetch_dest/under_dir/second")).thenReturn(DigestUtils.md5Hex("Second File"));

    dirHandler.handle(new FileInputStream(zip));
    dirHandler.handleResult(200, goPublisher);

    assertThat(goPublisher.getMessage(), containsString(
            String.format("Saved artifact to [%s] after verifying the integrity of its contents.", agentDest)));
    assertThat(goPublisher.getMessage(), not(containsString("[WARN]")));
    assertArtifactWasSaved("under_dir");
}

From source file:jenkins.plugins.publish_over.helper.InputStreamMatcher.java

public boolean matches(final Object argument) {
    if (!(argument instanceof InputStream))
        return false;

    try {/*from  w  ww  . ja  v  a  2 s .com*/
        final byte[] actual = IOUtils.toByteArray((InputStream) argument);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Expected (md5) = " + DigestUtils.md5Hex(expectedContents));
            LOG.debug("Actual   (md5) = " + DigestUtils.md5Hex(actual));
        }
        return Arrays.equals(expectedContents, actual);
    } catch (IOException ioe) {
        throw new RuntimeException("Failed to read contents of InputStream", ioe);
    }
}

From source file:com.collaide.fileuploader.helper.TestHelper.java

protected String getMd5(File file) {
    try {//  ww  w.j av  a2  s . c  om
        FileInputStream fis = new FileInputStream(file);
        return DigestUtils.md5Hex(fis);
    } catch (IOException ex) {
        java.util.logging.Logger.getLogger(TestHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}