Package org.apache.commons.compress.compressors

Examples of org.apache.commons.compress.compressors.CompressorOutputStream


      } else {
        // unix: download a tar.gz file with pt.py set with execute permissions
        response.setHeader("Content-Disposition", "attachment; filename=\"pt.tar.gz\"");

        OutputStream os = response.getOutputStream();
        CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.GZIP, os);
        TarArchiveOutputStream tos = new TarArchiveOutputStream(cos);
        tos.setAddPaxHeadersForNonAsciiNames(true);
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

        // add the Python script
        TarArchiveEntry pyEntry = new TarArchiveEntry("pt");
        pyEntry.setMode(FileMode.EXECUTABLE_FILE.getBits());
        pyEntry.setModTime(lastModified);
        pyEntry.setSize(pyBytes.length);
        tos.putArchiveEntry(pyEntry);
        tos.write(pyBytes);
        tos.closeArchiveEntry();

        // add a brief readme
        byte [] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt"));
        TarArchiveEntry txtEntry = new TarArchiveEntry("README");
        txtEntry.setMode(FileMode.REGULAR_FILE.getBits());
        txtEntry.setModTime(lastModified);
        txtEntry.setSize(txtBytes.length);
        tos.putArchiveEntry(txtEntry);
        tos.write(txtBytes);
        tos.closeArchiveEntry();

        // cleanup
        tos.finish();
        tos.close();
        cos.close();
        os.flush();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here


        if (destination.isDirectory()) {
            destination = new File(destination, getCompressedFilename(source));
        }

        CompressorOutputStream compressed = null;
        BufferedInputStream input = null;
        try {
            input = new BufferedInputStream(new FileInputStream(source));
            compressed = createCompressorOutputStream(this, destination);
View Full Code Here

      } else {
        // unix: download a tar.gz file with pt.py set with execute permissions
        response.setHeader("Content-Disposition", "attachment; filename=\"pt.tar.gz\"");

        OutputStream os = response.getOutputStream();
        CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.GZIP, os);
        TarArchiveOutputStream tos = new TarArchiveOutputStream(cos);
        tos.setAddPaxHeadersForNonAsciiNames(true);
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

        // add the Python script
        TarArchiveEntry pyEntry = new TarArchiveEntry("pt");
        pyEntry.setMode(FileMode.EXECUTABLE_FILE.getBits());
        pyEntry.setModTime(lastModified);
        pyEntry.setSize(pyBytes.length);
        tos.putArchiveEntry(pyEntry);
        tos.write(pyBytes);
        tos.closeArchiveEntry();

        // add a brief readme
        byte [] txtBytes = readAll(getClass().getResourceAsStream("/pt.txt"));
        TarArchiveEntry txtEntry = new TarArchiveEntry("README");
        txtEntry.setMode(FileMode.REGULAR_FILE.getBits());
        txtEntry.setModTime(lastModified);
        txtEntry.setSize(txtBytes.length);
        tos.putArchiveEntry(txtEntry);
        tos.write(txtBytes);
        tos.closeArchiveEntry();

        // cleanup
        tos.finish();
        tos.close();
        cos.close();
        os.flush();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

        final File output = new File(file.getParent(), file.getName() + ".gz");
        output.delete();

        final OutputStream out = new FileOutputStream(output);

        final CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("gz", out);
        final FileInputStream is = new FileInputStream(file);
        IOUtils.copy(is, cos);

        is.close();
        cos.close();
        out.close();

        return output;
    }
View Full Code Here

        final File output = new File(file.getParent(), file.getName() + ".gz");
        output.delete();

        final OutputStream out = new FileOutputStream(output);

        final CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("gz", out);
        final FileInputStream is = new FileInputStream(file);
        IOUtils.copy(is, cos);

        is.close();
        cos.close();
        out.close();

        return output;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.compressors.CompressorOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.