List of usage examples for java.util.zip GZIPOutputStream close
public void close() throws IOException
From source file:com.giacomodrago.immediatecrypt.messagecipher.Compression.java
public static byte[] compress(byte[] plaintext) { try {/*from w ww.j av a 2 s. com*/ ByteArrayOutputStream writer = new ByteArrayOutputStream(); GZIPOutputStream gzipStream = new GZIPOutputStream(writer); gzipStream.write(plaintext); gzipStream.flush(); gzipStream.close(); writer.close(); return writer.toByteArray(); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:Main.java
public static byte[] compressInGzip(byte[] originalData, int offset, int length) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream gzipOutStream = new GZIPOutputStream(bos); gzipOutStream.write(originalData, offset, length); gzipOutStream.finish();/*from www . j a v a 2s . co m*/ gzipOutStream.flush(); gzipOutStream.close(); byte[] compressData = bos.toByteArray(); bos.close(); return compressData; }
From source file:azkaban.utils.GZIPUtils.java
public static byte[] gzipBytes(byte[] bytes, int offset, int length) throws IOException { ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); GZIPOutputStream gzipStream = null; gzipStream = new GZIPOutputStream(byteOutputStream); gzipStream.write(bytes, offset, length); gzipStream.close(); return byteOutputStream.toByteArray(); }
From source file:ZipDemo.java
public static final byte[] compress(final String uncompressed) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream zos = new GZIPOutputStream(baos); byte[] uncompressedBytes = uncompressed.getBytes(); zos.write(uncompressedBytes, 0, uncompressedBytes.length); zos.close(); return baos.toByteArray(); }
From source file:com.google.api.server.spi.IoUtilTest.java
private static byte[] compress(byte[] bytes) { try {//from w w w . j av a 2 s . c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gos = new GZIPOutputStream(baos); gos.write(bytes, 0, bytes.length); gos.close(); return baos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.cenrise.test.azkaban.GZIPUtils.java
public static byte[] gzipBytes(final byte[] bytes, final int offset, final int length) throws IOException { final ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); GZIPOutputStream gzipStream = null; gzipStream = new GZIPOutputStream(byteOutputStream); gzipStream.write(bytes, offset, length); gzipStream.close(); return byteOutputStream.toByteArray(); }
From source file:org.geppetto.frontend.messaging.CompressionUtils.java
public static byte[] gzipCompress(byte[] message) throws IOException { long startTime = System.currentTimeMillis(); ByteArrayOutputStream compressedMessageStream = new ByteArrayOutputStream(); GZIPOutputStream gzipOutputStream = new GZIPOutputStream(compressedMessageStream); gzipOutputStream.write(message);//www .ja v a 2 s .c o m gzipOutputStream.close(); byte[] compressedMessage = compressedMessageStream.toByteArray(); compressedMessageStream.close(); long elapsedTime = System.currentTimeMillis() - startTime; logger.info(String.format("Compressed message from %d to %d bytes in %dms", message.length, compressedMessage.length, elapsedTime)); return compressedMessage; }
From source file:Main.java
public static byte[] compressStringToByteArray(String uncompressedString) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); GZIPOutputStream gzipOutputStream; try {/*from w w w . ja v a 2s . c o m*/ gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream); gzipOutputStream.write(uncompressedString.getBytes("UTF-8")); gzipOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } return byteArrayOutputStream.toByteArray(); }
From source file:org.geppetto.frontend.messaging.CompressionUtils.java
public static byte[] gzipCompress(String message) throws IOException { long startTime = System.currentTimeMillis(); ByteArrayOutputStream compressedMessageStream = new ByteArrayOutputStream(); GZIPOutputStream gzipOutputStream = new GZIPOutputStream(compressedMessageStream); gzipOutputStream.write(message.getBytes()); gzipOutputStream.close(); byte[] compressedMessage = compressedMessageStream.toByteArray(); compressedMessageStream.close();/* w w w.ja va 2s .c o m*/ long elapsedTime = System.currentTimeMillis() - startTime; logger.info(String.format("Compressed message from %d to %d bytes in %dms", message.length(), compressedMessage.length, elapsedTime)); return compressedMessage; }
From source file:v7db.files.Compression.java
/** * @return null, if the "gzipped" data is larger than the input (or there * has been an exception)//from w w w . j ava2s . c om */ public static byte[] gzip(byte[] data, int off, int len) { if (len < GZIP_STORAGE_OVERHEAD) return null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length); GZIPOutputStream gz = new GZIPOutputStream(baos); gz.write(data, off, len); gz.close(); if (baos.size() >= len) return null; return baos.toByteArray(); } catch (Exception e) { log.error("failed to gzip byte array", e); return null; } }