List of usage examples for java.util.zip GZIPOutputStream GZIPOutputStream
public GZIPOutputStream(OutputStream out) throws IOException
From source file:edu.cornell.med.icb.goby.algorithmic.data.WeightsInfo.java
/** * Save weights info to disk.//from w w w. j a v a2s .co m * * @param filename The name of the file to save to * @throws IOException If the file cannot be written */ public void save(final String filename) throws IOException { GZIPOutputStream gzipOutputStream = null; try { gzipOutputStream = new GZIPOutputStream(new FileOutputStream(filename)); BinIO.storeObject(this, gzipOutputStream); gzipOutputStream.flush(); LOG.info("Saved " + filename); } finally { IOUtils.closeQuietly(gzipOutputStream); } }
From source file:com.github.k0zka.contentcompress.ContentGzipMojo.java
void compress(final File directory, final String fileName) throws IOException { final File sourceFile = new File(directory, fileName); final File gzippedFile = new File(directory, fileName.concat(".gz")); if (gzippedFile.exists() && gzippedFile.lastModified() > sourceFile.lastModified()) { getLog().info("Skipped file " + sourceFile.getName() + " .gz is up to date"); return;// www. j a v a2s .c o m } final FileInputStream inputStream = new FileInputStream(sourceFile); final FileOutputStream fileStream = new FileOutputStream(gzippedFile); final GZIPOutputStream gzipStream = new GZIPOutputStream(fileStream); IOUtils.copy(inputStream, gzipStream); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(gzipStream); IOUtils.closeQuietly(fileStream); final long sourceLength = sourceFile.length(); final long gzipedLength = gzippedFile.length(); if (sourceLength > gzipedLength) { getLog().info("Compressed file " + sourceFile.getName() + ". " + sourceLength + " -> " + gzipedLength); } else { getLog().info("Compressed file " + sourceFile.getName() + ". " + sourceLength + " -> " + gzipedLength + " removing, gzipped version is bigger"); gzippedFile.delete(); } }
From source file:com.spstudio.common.image.ImageUtils.java
/** * byte[]//from w w w .j a va 2s .c o m * * @param ?? * @return ?? */ public static byte[] compress(byte[] data) { System.out.println("before:" + data.length); GZIPOutputStream gzip = null; ByteArrayOutputStream baos = null; byte[] newData = null; try { baos = new ByteArrayOutputStream(); gzip = new GZIPOutputStream(baos); gzip.write(data); gzip.finish(); gzip.flush(); newData = baos.toByteArray(); } catch (IOException e) { e.printStackTrace(); } finally { try { gzip.close(); baos.close(); } catch (IOException e) { e.printStackTrace(); } } System.out.println("after:" + newData.length); return newData; }
From source file:org.calrissian.accumulorecipes.blobstore.impl.ext.ExtendedAccumuloBlobStoreTest.java
@Test public void testSaveAndQueryComplex() throws Exception { ExtendedAccumuloBlobStore blobStore = new ExtendedAccumuloBlobStore(getConnector(), CHUNK_SIZE); Collection<String> testValues = new ArrayList<String>(10); for (int i = 0; i < CHUNK_SIZE; i++) testValues.add(randomUUID().toString()); //Store json in a Gzipped format OutputStream storageStream = blobStore.store("test", "1", currentTimeMillis(), ""); mapper.writeValue(new GZIPOutputStream(storageStream), testValues); //reassemble the json after unzipping the stream. InputStream retrievalStream = blobStore.get("test", "1", Auths.EMPTY); Collection<String> actualValues = mapper.readValue(new GZIPInputStream(retrievalStream), strColRef); //if there were no errors, then verify that the two collections are equal. assertThat(actualValues, is(equalTo(testValues))); }
From source file:io.github.azige.whitespace.Cli.java
static void compile(InputStream input, String path) throws IOException { Interpreter interpreter = createInterpreter(); Program program = interpreter.interpret(createReader(input)); path = path.replaceFirst("\\.[^\\.]+$", WHITESPACE_BINARY_FILE_SUFFIX); try (ObjectOutputStream output = new ObjectOutputStream( new GZIPOutputStream(Files.newOutputStream(Paths.get(path))))) { output.writeObject(program);/*from w w w. ja va 2 s. c o m*/ } }
From source file:hr.fer.zemris.vhdllab.platform.remoting.HttpClientRequestExecutor.java
@Override protected OutputStream decorateOutputStream(OutputStream os) throws IOException { return new GZIPOutputStream(os); }
From source file:org.envirocar.app.network.HTTPClient.java
public static HttpEntity createEntity(byte[] data) throws IOException { AbstractHttpEntity entity;/*ww w . j av a2 s . co m*/ if (data.length < MIN_GZIP_SIZE) { entity = new ByteArrayEntity(data); } else { ByteArrayOutputStream arr = new ByteArrayOutputStream(); OutputStream zipper = new GZIPOutputStream(arr); zipper.write(data); zipper.close(); entity = new ByteArrayEntity(arr.toByteArray()); entity.setContentEncoding("gzip"); } return entity; }
From source file:com.ery.ertc.estorm.util.GZIPUtils.java
public static final byte[] zip(byte[] in, int offset, int length) { try {/*from w w w .ja va2s. c o m*/ // compress using GZIPOutputStream ByteArrayOutputStream byteOut = new ByteArrayOutputStream(length / EXPECTED_COMPRESSION_RATIO); GZIPOutputStream outStream = new GZIPOutputStream(byteOut); try { outStream.write(in, offset, length); } catch (Exception e) { LOG.error("Failed to get outStream.write input", e); } try { outStream.close(); } catch (IOException e) { LOG.error("Failed to implement outStream.close", e); } return byteOut.toByteArray(); } catch (IOException e) { LOG.error("Failed with IOException", e); return null; } }
From source file:edu.umn.cs.spatialHadoop.visualization.FrequencyMap.java
@Override public void write(DataOutput out) throws IOException { super.write(out); ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(baos); ByteBuffer bbuffer = ByteBuffer.allocate(getHeight() * 4 + 8); bbuffer.putInt(getWidth());// w w w .ja va 2 s. c om bbuffer.putInt(getHeight()); gzos.write(bbuffer.array(), 0, bbuffer.position()); for (int x = 0; x < getWidth(); x++) { bbuffer.clear(); for (int y = 0; y < getHeight(); y++) { bbuffer.putFloat(frequencies[x][y]); } gzos.write(bbuffer.array(), 0, bbuffer.position()); } gzos.close(); byte[] serializedData = baos.toByteArray(); out.writeInt(serializedData.length); out.write(serializedData); }
From source file:de.zib.scalaris.examples.wikipedia.data.Revision.java
/** * Compresses the given text and returns it as a byte array. * //w w w . j a va2 s . c o m * @param text * the un-compressed text * * @return the compressed text * * @throws RuntimeException * if compressing the text did not work */ protected static byte[] packText(String text) throws RuntimeException { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream gos = new GZIPOutputStream(bos); gos.write(text.getBytes("UTF-8")); gos.flush(); gos.close(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }