List of usage examples for java.util.zip GZIPOutputStream GZIPOutputStream
public GZIPOutputStream(OutputStream out) throws IOException
From source file:ezbake.deployer.utilities.Utilities.java
public static void appendFilesInTarArchive(OutputStream output, byte[] currentArchive, Iterable<ArtifactDataEntry> filesToAdd) throws DeploymentException { ArchiveStreamFactory asf = new ArchiveStreamFactory(); try (GZIPOutputStream gzs = new GZIPOutputStream(output)) { try (ArchiveOutputStream aos = asf.createArchiveOutputStream(ArchiveStreamFactory.TAR, gzs)) { try (GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(currentArchive))) { try (TarArchiveInputStream tarInputStream = new TarArchiveInputStream(gzip)) { TarArchiveEntry tarEntry = null; while ((tarEntry = tarInputStream.getNextTarEntry()) != null) { aos.putArchiveEntry(tarEntry); IOUtils.copy(tarInputStream, aos); aos.closeArchiveEntry(); }//from w ww.j av a 2 s . co m } } for (ArtifactDataEntry entry : filesToAdd) { aos.putArchiveEntry(entry.getEntry()); IOUtils.write(entry.getData(), aos); aos.closeArchiveEntry(); } } } catch (ArchiveException e) { log.error(e.getMessage(), e); throw new DeploymentException(e.getMessage()); } catch (IOException e) { log.error(e.getMessage(), e); throw new DeploymentException(e.getMessage()); } }
From source file:com.googlesource.gerrit.plugins.github.velocity.VelocityStaticServlet.java
private static byte[] compress(final byte[] raw) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final GZIPOutputStream gz = new GZIPOutputStream(out); gz.write(raw);//w ww . j a v a2 s. c o m gz.finish(); gz.flush(); return out.toByteArray(); }
From source file:de.tudarmstadt.ukp.dkpro.tc.mallet.util.MalletUtils.java
public static void writeFeatureNamesToFile(FeatureStore instanceList, File outputFile) throws IOException { BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(outputFile)), "UTF-8")); HashMap<String, Integer> featureOffsetIndex = new HashMap<String, Integer>(); for (int i = 0; i < instanceList.getNumberOfInstances(); i++) { Instance instance = instanceList.getInstance(i); for (Feature feature : instance.getFeatures()) { String featureName = feature.getName(); if (!featureOffsetIndex.containsKey(featureName)) { featureOffsetIndex.put(featureName, featureOffsetIndex.size()); bw.write(featureName + " "); }// w w w . jav a2 s. co m } } bw.write(MalletTestTask.OUTCOME_CLASS_LABEL_NAME); bw.close(); }
From source file:net.sf.ehcache.distribution.PayloadUtil.java
/** * Gzips a byte[]. For text, approximately 10:1 compression is achieved. * @param ungzipped the bytes to be gzipped * @return gzipped bytes/*from ww w. j a va2s . c om*/ */ public static byte[] gzip(byte[] ungzipped) { final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try { final GZIPOutputStream gzipOutputStream = new GZIPOutputStream(bytes); gzipOutputStream.write(ungzipped); gzipOutputStream.close(); } catch (IOException e) { LOG.fatal("Could not gzip " + ungzipped); } return bytes.toByteArray(); }
From source file:com.ttech.cordovabuild.infrastructure.archive.ArchiveUtils.java
public static void compressDirectory(Path path, OutputStream output) { try {/* w w w.java 2 s .c o m*/ // Wrap the output file stream in streams that will tar and gzip everything TarArchiveOutputStream taos = new TarArchiveOutputStream(new GZIPOutputStream(output)); // TAR has an 8 gig file limit by default, this gets around that taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR); // to get past the 8 gig limit // TAR originally didn't support long file names, so enable the support for it taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); for (File child : path.toFile().listFiles()) { addFileToTarGz(taos, child.toPath(), ""); } taos.close(); } catch (IOException e) { throw new ApplicationSourceException(e); } }
From source file:com.puppetlabs.geppetto.forge.v2.api.it.ReleaseTestCreate.java
private byte[] getReleaseImage(ModuleName moduleName, Version version) throws IOException { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); TarArchiveOutputStream tarImage = null; try {//w w w .j a v a2 s. c o m tarImage = new TarArchiveOutputStream(new GZIPOutputStream(bytesOut)); putEntry(tarImage, moduleName, version, "metadata.json", createMetadata(moduleName, version).toString()); putEntry(tarImage, moduleName, version, "manifests/init.pp", createInitPP(moduleName)); } finally { if (tarImage != null) tarImage.close(); } return bytesOut.toByteArray(); }
From source file:NGzipCompressingEntity.java
public void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException { if (baos == null) { baos = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(baos); InputStream in = wrappedEntity.getContent(); byte[] tmp = new byte[2048]; int l;/* w w w. j ava 2s . c o m*/ while ((l = in.read(tmp)) != -1) { gzip.write(tmp, 0, l); } gzip.close(); buffer = ByteBuffer.wrap(baos.toByteArray()); } encoder.write(buffer); if (!buffer.hasRemaining()) encoder.complete(); }
From source file:com.evilco.license.server.encoder.CompressedLicenseEncoder.java
/** * {@inheritDoc}/*from w ww . j a va2 s. c om*/ */ @Override public String encode(@Nonnull ILicense license) throws LicenseEncoderException { // define streams ByteArrayOutputStream outputStream = null; GZIPOutputStream gzipOutputStream = null; DataOutputStream dataOutputStream = null; // encode data try { // create stream instances outputStream = new ByteArrayOutputStream(); gzipOutputStream = new GZIPOutputStream(outputStream); dataOutputStream = new DataOutputStream(gzipOutputStream); // encode data this.childEncoder.encode(license, dataOutputStream); // flush buffers gzipOutputStream.flush(); outputStream.flush(); } catch (IOException ex) { throw new LicenseEncoderException(ex); } finally { IOUtils.closeQuietly(dataOutputStream); IOUtils.closeQuietly(gzipOutputStream); IOUtils.closeQuietly(outputStream); } // Encode Base64 String licenseText = BaseEncoding.base64().encode(outputStream.toByteArray()); // split text into chunks Joiner joiner = Joiner.on("\n").skipNulls(); return joiner.join(Splitter.fixedLength(LICENSE_CHUNK_WIDTH).split(licenseText)); }
From source file:edu.cornell.med.icb.goby.algorithmic.data.HeptamerInfo.java
/** * Save heptamer info to disk./*from ww w . j ava2 s . c o m*/ * * @param filename * @throws IOException * @throws ClassNotFoundException */ public void save(final String filename) throws IOException { GZIPOutputStream gzipOutputStream = null; try { gzipOutputStream = new GZIPOutputStream(new FileOutputStream(filename)); BinIO.storeObject(this, gzipOutputStream); } finally { IOUtils.closeQuietly(gzipOutputStream); } }
From source file:carmen.utils.Utils.java
public static Writer createWriter(String outputFile) throws UnsupportedEncodingException, IOException, FileNotFoundException { if (outputFile.endsWith(".gz")) { return new BufferedWriter( new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(outputFile)), "UTF-8")); } else {/*from w w w . jav a 2 s .com*/ return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")); } }