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.talis.storage.s3.cache.MemcachedChunkHandlerTest.java

private String getMemcachedKey(String key) {
    return DigestUtils.md5Hex(bucketname + "/" + key);
}

From source file:co.cask.hydrator.plugin.Hasher.java

@Override
public void transform(StructuredRecord in, Emitter<StructuredRecord> emitter) throws Exception {
    StructuredRecord.Builder builder = StructuredRecord.builder(in.getSchema());

    List<Schema.Field> fields = in.getSchema().getFields();
    for (Schema.Field field : fields) {
        String name = field.getName();
        if (fieldSet.contains(name) && field.getSchema().getType() == Schema.Type.STRING) {
            String value = in.get(name);
            String digest = value;
            switch (config.hash.toLowerCase()) {
            case "md2":
                digest = DigestUtils.md2Hex(value);
                break;
            case "md5":
                digest = DigestUtils.md5Hex(value);
                break;
            case "sha1":
                digest = DigestUtils.sha1Hex(value);
                break;
            case "sha256":
                digest = DigestUtils.sha256Hex(value);
                break;
            case "sha384":
                digest = DigestUtils.sha384Hex(value);
                break;
            case "sha512":
                digest = DigestUtils.sha512Hex(value);
                break;
            }/*from   w  w  w.j av  a 2s . co m*/
            builder.set(name, digest);
        } else {
            builder.set(name, in.get(name));
        }
    }
    emitter.emit(builder.build());
}

From source file:com.yahoo.parsec.gradle.utils.FileUtils.java

/**
 * Write resource to file./*from www  . j a va2s .c om*/
 *
 * @param inputStream input stream
 * @param outputFile  output file
 * @param overwrite   overwrite flag
 * @throws IOException IOException
 */
public void writeResourceToFile(final InputStream inputStream, String outputFile, boolean overwrite)
        throws IOException {
    File file = new File(outputFile);
    String outputFileDigest = "";

    if (file.exists()) {
        if (!overwrite) {
            logger.info("Skipping pre-existing " + outputFile);
            return;
        } else {
            try (InputStream outputFileStream = new FileInputStream(file)) {
                outputFileDigest = DigestUtils.md5Hex(outputFileStream);
            } catch (IOException e) {
                throw e;
            }
        }
    }

    try {
        byte[] bytes = IOUtils.toByteArray(inputStream);
        if (DigestUtils.md5Hex(bytes).equals(outputFileDigest)) {
            logger.info("Skipping unmodified " + outputFile);
            return;
        } else {
            logger.info("Creating file " + outputFile);
            Files.copy(new ByteArrayInputStream(bytes), Paths.get(outputFile),
                    StandardCopyOption.REPLACE_EXISTING);
        }
    } catch (IOException e) {
        throw e;
    }
}

From source file:com.jaeksoft.searchlib.streamlimiter.StreamLimiter.java

public String getMD5Hash() throws NoSuchAlgorithmException, LimitException, IOException {
    if (outputCache == null)
        loadOutputCache();// w  ww  .  j av a2 s .co m
    if (outputCache == null)
        return null;
    InputStream is = null;
    try {
        is = getNewInputStream();
        return DigestUtils.md5Hex(is);
    } finally {
        IOUtils.close(is);
    }
}

From source file:gov.nih.nci.cabig.caaers.service.adverseevent.AdditionalInformationDocumentService.java

public AdditionalInformationDocument uploadFile(String fileName, AdditionalInformation additionalInformation,
        InputStream inputStream, AdditionalInformationDocumentType additionalInformationDocumentType) {

    try {//from  w  w  w  .j  av a2  s  .c o  m

        String aeAttachmentsLocation = configuration.get(Configuration.AE_ATTACHMENTS_LOCATION);

        String directory = FilenameUtils.normalize(aeAttachmentsLocation + "/" + additionalInformation.getId());

        String extension = StringUtils.isNotBlank(FilenameUtils.getExtension(fileName))
                ? "." + FilenameUtils.getExtension(fileName)
                : "";

        String filePath = FilenameUtils.normalize(directory + "/" + FilenameUtils.getBaseName(fileName)
                + Calendar.getInstance().getTimeInMillis() + RandomUtils.nextInt(100) + extension);

        if (logger.isDebugEnabled()) {
            logger.debug(String.format("creating file  %s of type %s for additional information %s at %s ",
                    fileName, additionalInformationDocumentType, additionalInformation.getId(), filePath));
        }

        FileUtils.forceMkdir(new File(directory));

        File file = new File(filePath);
        if (file.createNewFile()) {
            long bytesCopied = IOUtils.copyLarge(inputStream, new FileOutputStream(file));

            AdditionalInformationDocument additionalInformationDocument = new AdditionalInformationDocument();
            additionalInformationDocument
                    .setAdditionalInformationDocumentType(additionalInformationDocumentType);
            additionalInformationDocument.setAdditionalInformation(additionalInformation);
            additionalInformationDocument.setFileId(DigestUtils.md5Hex(file.getAbsolutePath()));
            additionalInformationDocument.setOriginalFileName(fileName);
            additionalInformationDocument.setFileName(file.getName());

            additionalInformationDocument.setFilePath(file.getCanonicalPath());
            additionalInformationDocument.setRelativePath(file.getAbsolutePath());
            additionalInformationDocument.setFileSize(bytesCopied);
            additionalInformationDocumentDao.save(additionalInformationDocument);
            if (logger.isDebugEnabled()) {
                logger.debug(String.format(
                        "successfully created file  %s of type %s for additional information %s at %s. File information is - %s ",
                        fileName, additionalInformationDocumentType, additionalInformation.getId(), filePath,
                        additionalInformationDocument));
            }

            return additionalInformationDocument;
        } else {
            String errorMessage = String.format(
                    "error while creating  file  %s of type %s for additional information %s ", fileName,
                    additionalInformationDocumentType, additionalInformation.getId());
            throw new RuntimeException(errorMessage);
        }
    } catch (Exception e) {
        String errorMessage = String.format(
                "error while creating  file  %s of type %s for additional information %s ", fileName,
                additionalInformationDocumentType, additionalInformation.getId());

        logger.error(errorMessage, e);
        return null;
    }

}

From source file:de.ks.file.FileStore.java

protected String getMd5(File file) {
    try {/*from  ww w  .  j  a v a  2 s .  c  o m*/
        return DigestUtils.md5Hex(new FileInputStream(file));
    } catch (IOException e) {
        log.error("Could not read md5 from file {}", file, e);
        throw new RuntimeException(e);
    }
}

From source file:com.bradmcevoy.http.http11.auth.DigestGenerator.java

String md5(String... ss) {
    String d = "";
    for (int i = 0; i < ss.length; i++) {
        if (i > 0)
            d += ":";
        d = d + ss[i];/*from w ww. j a va  2s.c o  m*/
    }
    return new String(DigestUtils.md5Hex(d));
}

From source file:br.com.livraria.bean.FuncionarioBean.java

public void editar() {
    try {//from   w  w  w  .ja  v  a2  s . c o m
        FuncionarioDAO funcionarioDAO = new FuncionarioDAO();
        funcionarioCadastro.setSenha(DigestUtils.md5Hex(funcionarioCadastro.getSenha()));
        funcionarioDAO.editar(funcionarioCadastro);

        FacesUtil.adicionarMsgInfo("Funcionrio editado com sucesso");
    } catch (RuntimeException ex) {
        FacesUtil.adicionarMsgError("Erro ao tentar editar od dados do funcionrio:" + ex.getMessage());
    }

}

From source file:com.thoughtworks.go.apiv2.dashboard.DashboardControllerDelegate.java

public Object index(Request request, Response response) throws IOException {
    if (goDashboardService.isFeatureToggleDisabled()) {
        response.status(424);/*from  w  w w .j  a  va  2  s . c o m*/
        return FEATURE_NOT_ENABLED;
    }
    if (!goDashboardService.hasEverLoadedCurrentState()) {
        response.status(202);
        return BEING_PROCESSED;
    }

    String selectedPipelinesCookie = request.cookie("selected_pipelines");
    Long userId = currentUserId(request);
    Username userName = currentUsername();

    PipelineSelections selectedPipelines = pipelineSelectionsService
            .getPersistedSelectedPipelines(selectedPipelinesCookie, userId);
    List<GoDashboardPipelineGroup> pipelineGroups = goDashboardService
            .allPipelineGroupsForDashboard(selectedPipelines, userName);
    String etag = DigestUtils.md5Hex(
            pipelineGroups.stream().map(GoDashboardPipelineGroup::etag).collect(Collectors.joining("/")));

    if (fresh(request, etag)) {
        return notModified(response);
    }

    setEtagHeader(response, etag);

    return writerForTopLevelObject(request, response, outputWriter -> PipelineGroupsRepresenter
            .toJSON(outputWriter, new DashboardFor(pipelineGroups, userName)));
}

From source file:io.vertx.tempmail.impl.TempMailClientImpl.java

@Override
public void getMessages(String email, Handler<AsyncResult<JsonObject>> handler) {
    log.debug("getMessages::" + email);
    doGenericRequest(String.format(getMessagesURL, DigestUtils.md5Hex(email)), handler);
}