Example usage for java.util.zip Deflater NO_COMPRESSION

List of usage examples for java.util.zip Deflater NO_COMPRESSION

Introduction

In this page you can find the example usage for java.util.zip Deflater NO_COMPRESSION.

Prototype

int NO_COMPRESSION

To view the source code for java.util.zip Deflater NO_COMPRESSION.

Click Source Link

Document

Compression level for no compression.

Usage

From source file:com.thoughtworks.go.buildsession.DownloadDirCommandExecutorTest.java

@Test
void downloadDirWithChecksum() throws Exception {
    File folder = temporaryFolder.newFolder("log");
    Files.write(Paths.get(folder.getPath(), "a"), "content for a".getBytes());
    Files.write(Paths.get(folder.getPath(), "b"), "content for b".getBytes());

    File zip = new ZipUtil().zip(folder, temporaryFolder.newFile("log.zip"), Deflater.NO_COMPRESSION);

    httpService.setupDownload("http://far.far.away/log.zip", zip);
    httpService.setupDownload("http://far.far.away/log.zip.md5",
            "s/log/a=524ebd45bd7de3616317127f6e639bd6\ns/log/b=83c0aa3048df233340203c74e8a93d7d");

    runBuild(downloadDir(map("url", "http://far.far.away/log.zip", "dest", "dest", "src", "s/log",
            "checksumUrl", "http://far.far.away/log.zip.md5")), Passed);
    File dest = new File(sandbox, "dest");

    assertThat(console.output()).contains(String
            .format("Saved artifact to [%s] after verifying the integrity of its contents", dest.getPath()));
    assertThat(FileUtils.readFileToString(new File(dest, "log/a"), UTF_8)).isEqualTo("content for a");
    assertThat(FileUtils.readFileToString(new File(dest, "log/b"), UTF_8)).isEqualTo("content for b");
}

From source file:com.thoughtworks.go.domain.builder.FetchArtifactBuilderBuildCommandTest.java

@BeforeEach
void setUp() throws Exception {
    File folder = temporaryFolder.newFolder("log");
    File consolelog = new File(folder, "console.log");
    folder.mkdirs();/*from   w  w w  .  ja v  a  2 s .com*/
    consolelog.createNewFile();
    File uniqueTempFile = new File(folder, UUID.randomUUID().toString());
    uniqueTempFile.createNewFile();
    zip = new ZipUtil().zip(folder, uniqueTempFile, Deflater.NO_COMPRESSION);
}

From source file:randori.compiler.bundle.io.BundleWriter.java

/**
 * Create a {@link IBundle}.//www.  j  a v  a  2  s  .co m
 * 
 * @param fileName path to write the file to.
 */
public BundleWriter(final String fileName) throws FileNotFoundException {
    // Ensure that the directory for the SWC exists.
    File outputFile = new File(fileName);
    File outputDirectory = new File(outputFile.getAbsoluteFile().getParent());
    outputDirectory.mkdirs();

    zipOutputStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(fileName)));
    zipOutputStream.setLevel(Deflater.NO_COMPRESSION);
}

From source file:com.headwire.aem.tooling.intellij.eclipse.stub.JarBuilder.java

public InputStream buildJar(final IFolder sourceDir) throws CoreException {

    ByteArrayOutputStream store = new ByteArrayOutputStream();

    JarOutputStream zos = null;//from ww  w  .  j  a  v  a2  s .  co m
    InputStream manifestInput = null;
    try {
        IResource manifestResource = sourceDir.findMember(JarFile.MANIFEST_NAME);
        if (manifestResource == null || manifestResource.getType() != IResource.FILE) {
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                    "No file named " + JarFile.MANIFEST_NAME + " found under " + sourceDir));
        }

        manifestInput = ((IFile) manifestResource).getContents();

        Manifest manifest = new Manifest(manifestInput);

        zos = new JarOutputStream(store);
        zos.setLevel(Deflater.NO_COMPRESSION);
        // manifest first
        final ZipEntry anEntry = new ZipEntry(JarFile.MANIFEST_NAME);
        zos.putNextEntry(anEntry);
        manifest.write(zos);
        zos.closeEntry();
        zipDir(sourceDir, zos, "");
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
    } finally {
        IOUtils.closeQuietly(zos);
        IOUtils.closeQuietly(manifestInput);
    }

    return new ByteArrayInputStream(store.toByteArray());
}

From source file:com.thoughtworks.go.server.web.FileView.java

private void setOutput(boolean needToZip, File file, HttpServletResponse response) throws IOException {
    ServletOutputStream out = response.getOutputStream();
    if (needToZip) {
        new ZipUtil().zip(file, out, Deflater.NO_COMPRESSION);
    } else {//from  w  w w.  j a  v a  2 s  . co  m
        try (FileInputStream input = new FileInputStream(file)) {
            IOUtils.copy(input, out, 32 * 1024);
        }
    }
    out.flush();
}

From source file:com.thoughtworks.go.domain.builder.FetchArtifactBuilderTest.java

@Before
public void setUp() throws Exception {
    File folder = temporaryFolder.newFolder("log");
    File consolelog = new File(folder, "console.log");
    folder.mkdirs();/*  w ww  . j a  va2s  . c om*/
    consolelog.createNewFile();

    File uniqueTempFile = new File(folder, UUID.randomUUID().toString());
    uniqueTempFile.createNewFile();

    zip = new ZipUtil().zip(folder, uniqueTempFile, Deflater.NO_COMPRESSION);
    toClean.add(folder);
    toClean.add(zip);
    dest = new File("dest");
    dest.mkdirs();
    toClean.add(dest);
    clock = new TestingClock();
    publisher = new StubGoPublisher();
    checksumFileHandler = mock(ChecksumFileHandler.class);
    urlService = mock(URLService.class);
    downloadAction = mock(DownloadAction.class);
}

From source file:com.thoughtworks.go.util.ZipUtilTest.java

@Test
void shouldZipFileAndUnzipIt() throws IOException {
    zipFile = zipUtil.zip(srcDir, temporaryFolder.newFile(), Deflater.NO_COMPRESSION);
    assertThat(zipFile.isFile()).isTrue();

    zipUtil.unzip(zipFile, destDir);// w  w w.  ja va  2s  .com
    File baseDir = new File(destDir, srcDir.getName());

    assertIsDirectory(new File(baseDir, emptyDir.getName()));
    assertIsDirectory(new File(baseDir, childDir1.getName()));

    File actual1 = new File(baseDir, file1.getName());
    assertThat(actual1.isFile()).isTrue();
    assertThat(fileContent(actual1)).isEqualTo(fileContent(file1));

    File actual2 = new File(baseDir, childDir1.getName() + File.separator + file2.getName());
    assertThat(actual2.isFile()).isTrue();
    assertThat(fileContent(actual2)).isEqualTo(fileContent(file2));
}

From source file:org.apache.flex.swc.io.SWCWriter.java

/**
 * @param filename path to write the file to.
 * @param compressLibrarySWF - true if the library will be built compressed,
 * false otherwise./*from   w ww .j  av a  2s.  co m*/
 * @param enableDebug - true if the library should be build with debug
 * enabled, false otherwise.
 * @param swfWriterFactory - factory for creating swf writers.
 */
public SWCWriter(final String filename, boolean compressLibrarySWF, boolean enableDebug,
        ISWFWriterFactory swfWriterFactory) throws FileNotFoundException {
    super(compressLibrarySWF, enableDebug, swfWriterFactory);

    // Ensure that the directory for the SWC exists.
    File outputFile = new File(filename);
    File outputDirectory = new File(outputFile.getAbsoluteFile().getParent());
    outputDirectory.mkdirs();

    zipOutputStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
    zipOutputStream.setLevel(Deflater.NO_COMPRESSION);
}

From source file:com.thoughtworks.go.util.ZipUtilTest.java

@Test
void shouldZipFileContentsAndUnzipIt() throws IOException {
    zipFile = zipUtil.zip(srcDir, temporaryFolder.newFile(), Deflater.NO_COMPRESSION);
    assertThat(zipFile.isFile()).isTrue();

    zipUtil.unzip(zipFile, destDir);//from w  w  w . j ava  2 s . c o  m
    File baseDir = new File(destDir, srcDir.getName());

    assertIsDirectory(new File(baseDir, emptyDir.getName()));
    assertIsDirectory(new File(baseDir, childDir1.getName()));

    File actual1 = new File(baseDir, file1.getName());
    assertThat(actual1.isFile()).isTrue();
    assertThat(fileContent(actual1)).isEqualTo(fileContent(file1));

    File actual2 = new File(baseDir, childDir1.getName() + File.separator + file2.getName());
    assertThat(actual2.isFile()).isTrue();
    assertThat(fileContent(actual2)).isEqualTo(fileContent(file2));
}

From source file:org.roda_project.commons_ip.utils.ZIPUtils.java

public static void zip(Map<String, ZipEntryInfo> files, OutputStream out, SIP sip, boolean createSipIdFolder,
        boolean isCompressed) throws IOException, InterruptedException, IPException {
    ZipOutputStream zos = new ZipOutputStream(out);
    if (isCompressed) {
        zos.setLevel(Deflater.DEFAULT_COMPRESSION);
    } else {//w w w. ja  va2 s. co  m
        zos.setLevel(Deflater.NO_COMPRESSION);
    }

    Set<String> nonMetsChecksumAlgorithms = new TreeSet<>();
    nonMetsChecksumAlgorithms.add(IPConstants.CHECKSUM_ALGORITHM);
    Set<String> metsChecksumAlgorithms = new TreeSet<>();
    metsChecksumAlgorithms.addAll(nonMetsChecksumAlgorithms);
    metsChecksumAlgorithms.addAll(sip.getExtraChecksumAlgorithms());

    int i = 0;
    for (ZipEntryInfo file : files.values()) {
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }

        file.prepareEntryforZipping();

        LOGGER.debug("Zipping file {}", file.getFilePath());
        ZipEntry entry;
        if (createSipIdFolder) {
            entry = new ZipEntry(sip.getId() + "/" + file.getName());
        } else {
            entry = new ZipEntry(file.getName());
        }

        zos.putNextEntry(entry);
        InputStream inputStream = Files.newInputStream(file.getFilePath());

        try {
            Map<String, String> checksums;
            if (file instanceof METSZipEntryInfo) {
                checksums = calculateChecksums(Optional.of(zos), inputStream, metsChecksumAlgorithms);
                METSZipEntryInfo metsEntry = (METSZipEntryInfo) file;
                metsEntry.setChecksums(checksums);
                metsEntry.setSize(metsEntry.getFilePath().toFile().length());
            } else {
                checksums = calculateChecksums(Optional.of(zos), inputStream, nonMetsChecksumAlgorithms);
            }

            LOGGER.debug("Done zipping file");
            String checksum = checksums.get(IPConstants.CHECKSUM_ALGORITHM);
            String checksumType = IPConstants.CHECKSUM_ALGORITHM;
            file.setChecksum(checksum);
            file.setChecksumAlgorithm(checksumType);
            if (file instanceof METSFileTypeZipEntryInfo) {
                METSFileTypeZipEntryInfo f = (METSFileTypeZipEntryInfo) file;
                f.getMetsFileType().setCHECKSUM(checksum);
                f.getMetsFileType().setCHECKSUMTYPE(checksumType);
            } else if (file instanceof METSMdRefZipEntryInfo) {
                METSMdRefZipEntryInfo f = (METSMdRefZipEntryInfo) file;
                f.getMetsMdRef().setCHECKSUM(checksum);
                f.getMetsMdRef().setCHECKSUMTYPE(checksumType);
            }
        } catch (NoSuchAlgorithmException e) {
            LOGGER.error("Error while zipping files", e);
        }
        zos.closeEntry();
        inputStream.close();
        i++;

        sip.notifySipBuildPackagingCurrentStatus(i);
    }

    zos.close();
    out.close();
}