List of usage examples for java.util.zip GZIPOutputStream close
public void close() throws IOException
From source file:org.apache.ignite.console.agent.handlers.AbstractListener.java
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override// w w w . j a va 2s . c o m public final void call(Object... args) { final Ack cb = safeCallback(args); args = removeCallback(args); try { final Map<String, Object> params; if (args == null || args.length == 0) params = Collections.emptyMap(); else if (args.length == 1) params = fromJSON(args[0], Map.class); else throw new IllegalArgumentException("Wrong arguments count, must be <= 1: " + Arrays.toString(args)); if (pool == null) pool = newThreadPool(); pool.submit(new Runnable() { @Override public void run() { try { Object res = execute(params); // TODO IGNITE-6127 Temporary solution until GZip support for socket.io-client-java. // See: https://github.com/socketio/socket.io-client-java/issues/312 // We can GZip manually for now. if (res instanceof RestResult) { RestResult restRes = (RestResult) res; ByteArrayOutputStream baos = new ByteArrayOutputStream(4096); Base64OutputStream b64os = new Base64OutputStream(baos); GZIPOutputStream gzip = new GZIPOutputStream(b64os); gzip.write(restRes.getData().getBytes()); gzip.close(); restRes.zipData(baos.toString()); } cb.call(null, toJSON(res)); } catch (Exception e) { cb.call(e, null); } } }); } catch (Exception e) { cb.call(e, null); } }
From source file:com.linkedin.r2.filter.compression.stream.TestStreamingCompression.java
@Test public void testGzipCompressor() throws IOException, InterruptedException, CompressionException, ExecutionException { StreamingCompressor compressor = new GzipCompressor(_executor); final byte[] origin = new byte[BUF_SIZE]; Arrays.fill(origin, (byte) 'b'); ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(out); IOUtils.write(origin, gzip);//from w ww.jav a 2s .c om gzip.close(); byte[] compressed = out.toByteArray(); testCompress(compressor, origin, compressed); testDecompress(compressor, origin, compressed); testCompressThenDecompress(compressor, origin); }
From source file:org.commoncrawl.util.ArcFileWriter.java
/** * Gzip passed bytes. Use only when bytes is small. * /*from w w w . j av a 2 s.c om*/ * @param bytes * What to gzip. * @return A gzip member of bytes. * @throws IOException */ private static byte[] gzip(byte[] bytes) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzipOS = new GZIPOutputStream(baos); gzipOS.write(bytes, 0, bytes.length); gzipOS.close(); return baos.toByteArray(); }
From source file:com.epam.wilma.compression.gzip.GzipCompressionService.java
/** * Compresses an {@link InputStream} object into gzip. * @param inputStream the inputstream that will be compressed * @return a {@link ByteArrayOutputStream} containing gzipped byte array *//* w w w.ja v a 2 s. c o m*/ @Override public ByteArrayOutputStream compress(final InputStream inputStream) { InputStream source = inputStream; ByteArrayOutputStream baos = outputStreamFactory.createByteArrayOutputStream(); try { GZIPOutputStream gout = gzipOutpuStreamFactory.createOutputStream(baos); //... Code to read from your original uncompressed data and write to gout. IOUtils.copy(source, gout); gout.finish(); gout.close(); } catch (IOException e) { throw new SystemException("Could not gzip message body!", e); } return baos; }
From source file:org.apache.xmlrpc.CommonsXmlRpcTransport.java
public InputStream sendXmlRpc(byte[] request) throws IOException, XmlRpcClientException { method = new PostMethod(url.toString()); method.setHttp11(http11);/* w w w.ja v a 2 s . c o m*/ method.setRequestHeader(new Header("Content-Type", "text/xml")); if (rgzip) method.setRequestHeader(new Header("Content-Encoding", "gzip")); if (gzip) method.setRequestHeader(new Header("Accept-Encoding", "gzip")); method.setRequestHeader(userAgentHeader); if (rgzip) { ByteArrayOutputStream lBo = new ByteArrayOutputStream(); GZIPOutputStream lGzo = new GZIPOutputStream(lBo); lGzo.write(request); lGzo.finish(); lGzo.close(); byte[] lArray = lBo.toByteArray(); method.setRequestBody(new ByteArrayInputStream(lArray)); method.setRequestContentLength(-1); } else method.setRequestBody(new ByteArrayInputStream(request)); URI hostURI = new URI(url.toString()); HostConfiguration hostConfig = new HostConfiguration(); hostConfig.setHost(hostURI); client.executeMethod(hostConfig, method); boolean lgzipo = false; Header lHeader = method.getResponseHeader("Content-Encoding"); if (lHeader != null) { String lValue = lHeader.getValue(); if (lValue != null) lgzipo = (lValue.indexOf("gzip") >= 0); } if (lgzipo) return (new GZIPInputStream(method.getResponseBodyAsStream())); else return method.getResponseBodyAsStream(); }
From source file:au.org.ala.layers.web.ObjectsService.java
/** * This method returns all objects associated with a field * * @param id//from ww w .j a v a 2 s .c om * @return */ @RequestMapping(value = "/objects/csv/{id}", method = RequestMethod.GET) public void fieldObjectAsCSV(@PathVariable("id") String id, HttpServletResponse resp) throws IOException { try { resp.setContentType("text/csv"); resp.setHeader("Content-Disposition", "attachment; filename=\"objects-" + id + ".csv.gz\""); GZIPOutputStream gzipped = new GZIPOutputStream(resp.getOutputStream()); objectDao.writeObjectsToCSV(gzipped, id); gzipped.flush(); gzipped.close(); } catch (Exception e) { logger.error(e.getMessage(), e); resp.sendError(500, "Problem performing download"); } }
From source file:com.ocp.picasa.GDataClient.java
private ByteArrayEntity getCompressedEntity(byte[] data) throws IOException { ByteArrayEntity entity;//www .jav a 2 s . c o m if (data.length >= MIN_GZIP_SIZE) { ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(data.length / 2); GZIPOutputStream gzipOutput = new GZIPOutputStream(byteOutput); gzipOutput.write(data); gzipOutput.close(); entity = new ByteArrayEntity(byteOutput.toByteArray()); } else { entity = new ByteArrayEntity(data); } return entity; }
From source file:org.csploit.android.core.System.java
public static String saveSession(String sessionName) throws IOException { StringBuilder builder = new StringBuilder(); String filename = mStoragePath + '/' + sessionName + ".dss", session; builder.append(SESSION_MAGIC + "\n"); // skip the network target synchronized (mTargets) { builder.append(mTargets.size() - 1).append("\n"); for (Target target : mTargets) { if (target.getType() != Target.Type.NETWORK) target.serialize(builder); }//from w ww . j av a 2s. c om } session = builder.toString(); FileOutputStream ostream = new FileOutputStream(filename); GZIPOutputStream gzip = new GZIPOutputStream(ostream); gzip.write(session.getBytes()); gzip.close(); mSessionName = sessionName; return filename; }
From source file:z.hol.net.http.entity.compress.GzipCompressingEntity.java
@Override public void writeTo(final OutputStream outstream) throws IOException { if (outstream == null) { throw new IllegalArgumentException("Output stream may not be null"); }// ww w . j a v a2 s . co m GZIPOutputStream gzip = new GZIPOutputStream(outstream); InputStream in = wrappedEntity.getContent(); byte[] tmp = new byte[2048]; int l; while ((l = in.read(tmp)) != -1) { gzip.write(tmp, 0, l); } gzip.close(); }
From source file:com.zimbra.common.util.ByteUtil.java
/** * compress the supplied data using GZIPOutputStream * and return the compressed data.//from w ww . ja v a 2 s .c o m * @param data data to compress * @return compressesd data */ public static byte[] compress(byte[] data) throws IOException { ByteArrayOutputStream baos = null; GZIPOutputStream gos = null; try { baos = new ByteArrayOutputStream(data.length); //data.length overkill gos = new GZIPOutputStream(baos); gos.write(data); gos.finish(); return baos.toByteArray(); } finally { if (gos != null) { gos.close(); } else if (baos != null) baos.close(); } }