Search in sources :

Example 1 with ChecksumValidator

use of com.thoughtworks.go.validation.ChecksumValidator in project gocd by gocd.

the class FileHandler method handle.

public void handle(InputStream stream) throws IOException {
    FileOutputStream fileOutputStream = null;
    try {
        fileOutputStream = FileUtils.openOutputStream(artifact);
        if (LOG.isInfoEnabled()) {
            LOG.info(format("[Artifact File Download] [%s] Download of artifact %s started", new Date(), artifact.getName()));
        }
        IOUtils.copyLarge(stream, fileOutputStream);
        if (LOG.isInfoEnabled()) {
            LOG.info(format("[Artifact File Download] [%s] Download of artifact %s ended", new Date(), artifact.getName()));
        }
    } finally {
        IOUtils.closeQuietly(fileOutputStream);
    }
    FileInputStream inputStream = null;
    try {
        inputStream = new FileInputStream(artifact);
        if (LOG.isInfoEnabled()) {
            LOG.info(format("[Artifact File Download] [%s] Checksum computation of artifact %s started", new Date(), artifact.getName()));
        }
        String artifactMD5 = md5Hex(inputStream);
        new ChecksumValidator(artifactMd5Checksums).validate(srcFile, artifactMD5, checksumValidationPublisher);
        if (LOG.isInfoEnabled()) {
            LOG.info(format("[Artifact File Download] [%s] Checksum computation of artifact %s ended", new Date(), artifact.getName()));
        }
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}
Also used : ChecksumValidator(com.thoughtworks.go.validation.ChecksumValidator) Date(java.util.Date)

Example 2 with ChecksumValidator

use of com.thoughtworks.go.validation.ChecksumValidator in project gocd by gocd.

the class DirHandler method handle.

public void handle(InputStream stream) throws IOException {
    ZipInputStream zipInputStream = new ZipInputStream(stream);
    LOG.info(format("[Agent Fetch Artifact] Downloading from '%s' to '%s'. Will read from Socket stream to compute MD5 and write to file", srcFile, destOnAgent.getAbsolutePath()));
    long before = System.currentTimeMillis();
    new ZipUtil(new ZipUtil.ZipEntryHandler() {

        public void handleEntry(ZipEntry entry, InputStream stream) throws IOException {
            LOG.info(format("[Agent Fetch Artifact] Downloading a directory from '%s' to '%s'. Handling the entry: '%s'", srcFile, destOnAgent.getAbsolutePath(), entry.getName()));
            new ChecksumValidator(artifactMd5Checksums).validate(getSrcFilePath(entry), md5Hex(stream), checksumValidationPublisher);
        }
    }).unzip(zipInputStream, destOnAgent);
    LOG.info(format("[Agent Fetch Artifact] Downloading a directory from '%s' to '%s'. Took: %sms", srcFile, destOnAgent.getAbsolutePath(), System.currentTimeMillis() - before));
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipUtil(com.thoughtworks.go.util.ZipUtil) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ChecksumValidator(com.thoughtworks.go.validation.ChecksumValidator)

Aggregations

ChecksumValidator (com.thoughtworks.go.validation.ChecksumValidator)2 ZipUtil (com.thoughtworks.go.util.ZipUtil)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1