List of usage examples for java.util.zip GZIPOutputStream write
public void write(int b) throws IOException
From source file:com.faceye.feature.util.http.GZIPUtils.java
/** * Returns an gzipped copy of the input array. *///from w ww . j ava 2 s. com public static final byte[] zip(byte[] in) { try { // compress using GZIPOutputStream ByteArrayOutputStream byteOut = new ByteArrayOutputStream(in.length / EXPECTED_COMPRESSION_RATIO); GZIPOutputStream outStream = new GZIPOutputStream(byteOut); try { outStream.write(in); } catch (Exception e) { LOG.error("Error writing outStream: ", e); } try { outStream.close(); } catch (IOException e) { LOG.error("Error closing outStream: ", e); } return byteOut.toByteArray(); } catch (IOException e) { LOG.error("Error: ", e); return null; } }
From source file:uk.ac.bbsrc.tgac.miso.integration.util.IntegrationUtils.java
public static byte[] compress(byte[] content) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Base64OutputStream b64os = new Base64OutputStream(baos); GZIPOutputStream gzip = new GZIPOutputStream(b64os); gzip.write(content); gzip.close();/*ww w . ja v a 2 s. com*/ return baos.toByteArray(); }
From source file:io.digibyte.tools.util.BRCompressor.java
public static byte[] gZipCompress(byte[] data) { if (data == null) return null; byte[] compressedData = null; try {//from w w w. j a v a2 s.c o m ByteArrayOutputStream byteStream = new ByteArrayOutputStream(data.length); try { GZIPOutputStream zipStream = new GZIPOutputStream(byteStream); try { zipStream.write(data); } finally { try { zipStream.close(); } catch (IOException e) { e.printStackTrace(); } } } finally { try { byteStream.close(); } catch (IOException e) { e.printStackTrace(); } } compressedData = byteStream.toByteArray(); } catch (Exception e) { BRReportsManager.reportBug(e); e.printStackTrace(); } return compressedData; }
From source file:org.commoncrawl.util.GZIPUtils.java
/** * Returns an gzipped copy of the input array. *//*from w w w . j a v a2 s.c o m*/ public static final byte[] zip(byte[] in) { try { // compress using GZIPOutputStream ByteArrayOutputStream byteOut = new ByteArrayOutputStream(in.length / EXPECTED_COMPRESSION_RATIO); GZIPOutputStream outStream = new GZIPOutputStream(byteOut); try { outStream.write(in); } catch (Exception e) { LOG.warn(CCStringUtils.stringifyException(e)); } try { outStream.close(); } catch (IOException e) { LOG.warn(CCStringUtils.stringifyException(e)); } return byteOut.toByteArray(); } catch (IOException e) { LOG.warn(CCStringUtils.stringifyException(e)); return null; } }
From source file:com.ery.ertc.estorm.util.GZIPUtils.java
/** * Returns an gzipped copy of the input array. */// w w w. j av a 2s . co m public static final byte[] zip(byte[] in) { try { // compress using GZIPOutputStream ByteArrayOutputStream byteOut = new ByteArrayOutputStream(in.length / EXPECTED_COMPRESSION_RATIO); GZIPOutputStream outStream = new GZIPOutputStream(byteOut); try { outStream.write(in); } 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:com.breadwallet.tools.util.BRCompressor.java
public static byte[] gZipCompress(byte[] data) { if (data == null) return null; byte[] compressedData = null; try {// w w w. j a v a2 s . c om ByteArrayOutputStream byteStream = new ByteArrayOutputStream(data.length); try { GZIPOutputStream zipStream = new GZIPOutputStream(byteStream); try { zipStream.write(data); } finally { try { zipStream.close(); } catch (IOException e) { e.printStackTrace(); } } } finally { try { byteStream.close(); } catch (IOException e) { e.printStackTrace(); } } compressedData = byteStream.toByteArray(); } catch (Exception e) { FirebaseCrash.report(e); e.printStackTrace(); } return compressedData; }
From source file:org.pentaho.di.cluster.HttpUtil.java
public static String encodeBase64ZippedString(String in) throws IOException { Charset charset = Charset.forName(Const.XML_ENCODING); ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream(baos); gzos.write(in.getBytes(charset)); gzos.close();/*from w w w . j a va2 s .c o m*/ return new String(Base64.encodeBase64(baos.toByteArray())); }
From source file:NettyServerHandler.java
public static String compress(String str) throws IOException { if (str == null || str.length() == 0) { return str; }//from w w w.j a v a 2s .c o m ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(out); gzip.write(str.getBytes()); gzip.close(); String outStr = out.toString("ISO-8859-1"); return outStr; }
From source file:rapture.util.StringUtil.java
/** * Compress the passed in string and base64 encode it * @param content/*from w w w . ja v a2 s . com*/ * @return */ public static String base64Compress(String content) { if (content == null || content.isEmpty()) { return content; } ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream gzip; try { gzip = new GZIPOutputStream(out); gzip.write(content.getBytes("UTF-8")); gzip.close(); } catch (IOException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Error compressing content", e); } // Now with out, base64 byte[] encoding = Base64.encodeBase64(out.toByteArray()); return new String(encoding); }
From source file:org.eclipse.smila.connectivity.framework.crawler.web.util.GZIPUtils.java
/** * Returns an gzipped copy of the input array. * /*from www . j a va2s . c om*/ * @param in * input byte array * @return byte gzipped copy of the input array */ public static byte[] zip(byte[] in) { try { // compress using GZIPOutputStream final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(in.length / EXPECTED_COMPRESSION_RATIO); final GZIPOutputStream outStream = new GZIPOutputStream(byteOut); try { outStream.write(in); } catch (Exception exception) { LOG.error(exception.getMessage()); } try { outStream.close(); } catch (IOException e) { LOG.error(e.getMessage()); } return byteOut.toByteArray(); } catch (IOException e) { LOG.error(e.getMessage()); return null; } }