Example usage for java.util.zip Deflater DEFAULT_COMPRESSION

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

Introduction

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

Prototype

int DEFAULT_COMPRESSION

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

Click Source Link

Document

Default compression level.

Usage

From source file:org.simbasecurity.core.saml.SAMLServiceImpl.java

protected String encodeSAMLRequest(byte[] pSAMLRequest) throws RuntimeException {
    Base64 base64Encoder = new Base64();

    try {//w w  w. j a va 2  s.  c o m
        ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
        Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true);

        DeflaterOutputStream def = new DeflaterOutputStream(byteArray, deflater);
        def.write(pSAMLRequest);
        def.close();
        byteArray.close();

        String stream = new String(base64Encoder.encode(byteArray.toByteArray()));

        return stream.trim();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.sonarsource.commandlinezip.ZipUtils7.java

public static void smartReportZip(final Path srcDir, Path zip) throws IOException {
    try (final OutputStream out = FileUtils.openOutputStream(zip.toFile());
            final ZipOutputStream zout = new ZipOutputStream(out)) {
        Files.walkFileTree(srcDir, new SimpleFileVisitor<Path>() {
            @Override//from  w  w w . j a  v  a  2  s  .  co m
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                try (InputStream in = new BufferedInputStream(new FileInputStream(file.toFile()))) {
                    String entryName = srcDir.relativize(file).toString();
                    int level = file.toString().endsWith(".pb") ? ZipOutputStream.STORED
                            : Deflater.DEFAULT_COMPRESSION;
                    zout.setLevel(level);
                    ZipEntry entry = new ZipEntry(entryName);
                    zout.putNextEntry(entry);
                    IOUtils.copy(in, zout);
                    zout.closeEntry();
                }
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                if (dir.equals(srcDir)) {
                    return FileVisitResult.CONTINUE;
                }

                String entryName = srcDir.relativize(dir).toString();
                ZipEntry entry = new ZipEntry(entryName);
                zout.putNextEntry(entry);
                zout.closeEntry();
                return FileVisitResult.CONTINUE;
            }
        });
    }
}

From source file:org.xdi.util.io.ResponseHelper.java

public static ZipOutputStream createZipStream(OutputStream output, String comment) {
    ZipOutputStream zos = new ZipOutputStream(output);

    zos.setComment("Shibboleth2 SP configuration files");
    zos.setMethod(ZipOutputStream.DEFLATED);
    zos.setLevel(Deflater.DEFAULT_COMPRESSION);

    return zos;/*from   w  w w .  java  2  s.co  m*/
}

From source file:org.xdi.zip.CompressionHelper.java

public static byte[] deflate(byte[] data, boolean nowrap) throws IOException {
    Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, nowrap);
    deflater.setInput(data);//from  ww w  . j a  v a 2s .com
    deflater.finish();

    ByteArrayOutputStream os = new ByteArrayOutputStream();

    try {
        byte[] buffer = new byte[1024];
        while (!deflater.finished()) {
            int count = deflater.deflate(buffer);
            os.write(buffer, 0, count);
        }
    } finally {
        IOUtils.closeQuietly(os);
    }

    return os.toByteArray();
}

From source file:rega.genotype.ui.util.GenotypeLib.java

public static void zip(File dir, OutputStream os) {
    byte[] buffer = new byte[1024 * 1024];

    try {/*from www  .j  a  va  2s  . co m*/

        ZipOutputStream out = new ZipOutputStream(os);

        out.setLevel(Deflater.DEFAULT_COMPRESSION);

        for (File f : dir.listFiles()) {
            FileInputStream in = new FileInputStream(f);

            //new entry, relative path
            out.putNextEntry(
                    new ZipEntry(f.getAbsolutePath().replace(dir.getAbsolutePath() + File.separatorChar, "")));

            int len;
            while ((len = in.read(buffer)) > 0) {
                out.write(buffer, 0, len);
            }

            out.closeEntry();
            in.close();
        }
        out.close();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}