List of usage examples for java.util.zip GZIPOutputStream close
public void close() throws IOException
From source file:com.faceye.feature.util.http.GZIPUtils.java
/** * Returns an gzipped copy of the input array. *///w ww. j a va 2 s .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("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:com.iflytek.spider.util.GZIPUtils.java
/** * Returns an gzipped copy of the input array. *//*from ww w. j a v a 2 s . 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) { e.printStackTrace(LogUtil.getWarnStream(LOG)); } try { outStream.close(); } catch (IOException e) { e.printStackTrace(LogUtil.getWarnStream(LOG)); } return byteOut.toByteArray(); } catch (IOException e) { e.printStackTrace(LogUtil.getWarnStream(LOG)); return null; } }
From source file:com.opengamma.web.analytics.json.Compressor.java
static void compressStream(InputStream inputStream, OutputStream outputStream) throws IOException { InputStream iStream = new BufferedInputStream(inputStream); GZIPOutputStream oStream = new GZIPOutputStream( new Base64OutputStream(new BufferedOutputStream(outputStream), true, -1, null), 2048); byte[] buffer = new byte[2048]; int bytesRead; while ((bytesRead = iStream.read(buffer)) != -1) { oStream.write(buffer, 0, bytesRead); }//from w w w . jav a 2 s . c o m oStream.close(); // this is necessary for the gzip and base64 streams }
From source file:de.zib.scalaris.examples.wikipedia.data.Revision.java
/** * Compresses the given text and returns it as a byte array. * //from ww w .j a va2 s.c om * @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); } }
From source file:org.commoncrawl.util.GZIPUtils.java
/** * Returns an gzipped copy of the input array. *///from w w w . j a v a 2s. 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:org.apache.juneau.rest.test.GzipTest.java
private static InputStream compress(String contents) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(contents.length() >> 1); GZIPOutputStream gos = new GZIPOutputStream(baos); gos.write(contents.getBytes());// w w w .j a va 2 s .co m gos.finish(); gos.close(); return new ByteArrayInputStream(baos.toByteArray()); }
From source file:com.ery.ertc.estorm.util.GZIPUtils.java
/** * Returns an gzipped copy of the input array. *//*w w w . j a v a2 s . 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.facebook.presto.bloomfilter.BloomFilter.java
public static byte[] compress(byte[] b) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(out); gzip.write(b);//from ww w.ja v a2 s . co m gzip.close(); return out.toByteArray(); }
From source file:Compress.java
/** Gzip the contents of the from file and save in the to file. */ public static void gzipFile(String from, String to) throws IOException { // Create stream to read from the from file FileInputStream in = new FileInputStream(from); // Create stream to compress data and write it to the to file. GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(to)); // Copy bytes from one stream to the other byte[] buffer = new byte[4096]; int bytes_read; while ((bytes_read = in.read(buffer)) != -1) out.write(buffer, 0, bytes_read); // And close the streams in.close();//from w ww . j a va 2 s.c o m out.close(); }
From source file:org.eclipse.smila.connectivity.framework.crawler.web.util.GZIPUtils.java
/** * Returns an gzipped copy of the input array. * //from w w w. j av a 2 s . c o m * @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; } }