public static byte[] gzip(byte[] data) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream out = new GZIPOutputStream(bos); out.write(data); out.close(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
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); } } session = builder.toString(); FileOutputStream ostream = new FileOutputStream(filename); GZIPOutputStream gzip = new GZIPOutputStream(ostream); gzip.write(session.getBytes()); gzip.close(); mSessionName = sessionName; return filename; }
private byte[] getPlaintextStorageXml() throws Exception { ByteArrayOutputStream plaintextByteArrayOutputStream = new ByteArrayOutputStream(); DataOutputStream plaintextOutputStream = new DataOutputStream(plaintextByteArrayOutputStream); plaintextOutputStream.writeInt(transferSettings.getType().getBytes().length); plaintextOutputStream.write(transferSettings.getType().getBytes()); GZIPOutputStream plaintextGzipOutputStream = new GZIPOutputStream(plaintextOutputStream); new Persister(new Format(0)).write(transferSettings, plaintextGzipOutputStream); plaintextGzipOutputStream.close(); return plaintextByteArrayOutputStream.toByteArray(); } }
public void handle(HttpExchange t) throws IOException { String query = t.getRequestURI().getRawQuery(); ByteArrayOutputStream response = this.response.get(); response.reset(); OutputStreamWriter osw = new OutputStreamWriter(response); TextFormat.write004(osw, registry.filteredMetricFamilySamples(parseQuery(query))); osw.flush(); osw.close(); response.flush(); response.close(); t.getResponseHeaders().set("Content-Type", TextFormat.CONTENT_TYPE_004); if (shouldUseCompression(t)) { t.getResponseHeaders().set("Content-Encoding", "gzip"); t.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0); final GZIPOutputStream os = new GZIPOutputStream(t.getResponseBody()); response.writeTo(os); os.close(); } else { t.getResponseHeaders().set("Content-Length", String.valueOf(response.size())); t.sendResponseHeaders(HttpURLConnection.HTTP_OK, response.size()); response.writeTo(t.getResponseBody()); } t.close(); }
private static byte[] compressIfNecessary(byte[] dataBytes) throws IOException { // enable compression when data is larger than 1KB int maxDataSizeUncompress = 1024; if (dataBytes.length < maxDataSizeUncompress) { return dataBytes; } ByteArrayOutputStream out = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(out); gzip.write(dataBytes); gzip.close(); return out.toByteArray(); }
/** Compresses the given file and removes the uncompressed file @param file name of the zip file @return Size of the zip file */ private long zipFile(String file) throws IOException { cleanDiskSpace(); if (hasSpace()) { String zipFile = file + ".gz"; FileInputStream is = new FileInputStream(file); GZIPOutputStream gout = new GZIPOutputStream(new FileOutputStream(zipFile)); byte[] buffer = new byte[1024]; int readSize; while ((readSize = is.read(buffer)) != -1) gout.write(buffer, 0, readSize); is.close(); gout.flush(); gout.close(); //delete uncompressed file new File(file).delete(); return (new File(zipFile).length()); } else { logger.error("No space available to create zip files after attempting clean up"); return 0; } }
File tempFile = File.createTempFile(pointSetId, ".json.gz"); FileOutputStream fos = new FileOutputStream(tempFile); GZIPOutputStream gos = new GZIPOutputStream(fos); gos.close(); fis.close();
public static byte[] compressGZIPAsString(String content, Charset charset) throws IOException { if (content == null || content.length() == 0) { return null; } GZIPOutputStream gzip; ByteArrayOutputStream out = new ByteArrayOutputStream(); gzip = new GZIPOutputStream(out); gzip.write(content.getBytes(charset)); gzip.close(); return out.toByteArray(); }
public String save(String sessionName) throws IOException { StringBuilder builder = new StringBuilder(); String filename = System.getStoragePath() + '/' + sessionName + ".dhs", buffer = null; builder.append( System.SESSION_MAGIC + "\n"); builder.append(mUserName == null ? "null" : mUserName).append("\n"); builder.append(mHTTPS).append("\n"); builder.append(mAddress).append("\n"); builder.append(mDomain).append("\n"); builder.append(mUserAgent).append("\n"); builder.append(mCookies.size()).append("\n"); for(HttpCookie cookie : mCookies.values()){ builder .append(cookie.getName()).append( "=" ).append(cookie.getValue()) .append( "; domain=").append(cookie.getDomain()) .append( "; path=/" ) .append( mHTTPS ? ";secure" : "" ) .append("\n"); } buffer = builder.toString(); FileOutputStream ostream = new FileOutputStream(filename); GZIPOutputStream gzip = new GZIPOutputStream(ostream); gzip.write(buffer.getBytes()); gzip.close(); return filename; }
protected void processDynamic(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { ContentCachingResponseWrapper wrapper = new ContentCachingResponseWrapper(response); chain.doFilter(request, wrapper); FastByteArrayOutputStream baos = new FastByteArrayOutputStream(1024); GZIPOutputStream zip = new GZIPOutputStream(baos); StreamUtils.copy(wrapper.getContentInputStream(), zip); zip.close(); response.addHeader("Content-Encoding", "gzip"); response.setContentLength(baos.size()); StreamUtils.copy(new ByteArrayInputStream(baos.toByteArray()), response.getOutputStream()); }
public static byte[] compressGZIPAsString(String content, Charset charset) throws IOException { if (content == null || content.length() == 0) { return null; } GZIPOutputStream gzip; ByteArrayOutputStream out = new ByteArrayOutputStream(); gzip = new GZIPOutputStream(out); gzip.write(content.getBytes(charset)); gzip.close(); return out.toByteArray(); }
/** * * @param fileWorkArea * @param fileNames */ protected void gzipAndDeleteFiles(FileWorkArea fileWorkArea, List<String> fileNames,boolean shouldDeleteOriginal){ for (String fileName : fileNames) { try { String fileNameWithPath = FilenameUtils.normalize(fileWorkArea.getFilePathLocation() + File.separator + fileName); FileInputStream fis = new FileInputStream(fileNameWithPath); FileOutputStream fos = new FileOutputStream(fileNameWithPath + ENCODING_EXTENSION); GZIPOutputStream gzipOS = new GZIPOutputStream(fos); byte[] buffer = new byte[1024]; int len; while ((len = fis.read(buffer)) != -1) { gzipOS.write(buffer, 0, len); } //close resources gzipOS.close(); fos.close(); fis.close(); if(shouldDeleteOriginal){ File originalFile = new File(fileNameWithPath); originalFile.delete(); } } catch (IOException e) { LOG.error("Error writing zip file.", e); } } }
GZIPOutputStream compressorStream = new GZIPOutputStream(compressedDigestOutputStream); DescriptorDigest layerDiffId = uncompressedLayerBlob.writeTo(compressorStream).getDigest(); compressorStream.close(); BlobDescriptor compressedBlobDescriptor = compressedDigestOutputStream.toBlobDescriptor(); DescriptorDigest layerDigest = compressedBlobDescriptor.getDigest();
public static byte[] gzip(byte[] data) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); GZIPOutputStream out = new GZIPOutputStream(bos); out.write(data); out.close(); return bos.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
OutputStreamWriter osw = new OutputStreamWriter(xlearningProcess.getOutputStream()); File gzFile = new File(conf.get(XLearningConfiguration.XLEARNING_INPUTFORMAT_CACHEFILE_NAME, XLearningConfiguration.DEFAULT_XLEARNING_INPUTFORMAT_CACHEFILE_NAME)); GZIPOutputStream gos = new GZIPOutputStream(new FileOutputStream(gzFile)); boolean isCache = conf.getBoolean(XLearningConfiguration.XLEARNING_INPUTFORMAT_CACHE, XLearningConfiguration.DEFAULT_XLEARNING_INPUTFORMAT_CACHE); List<InputSplit> inputs = Arrays.asList(amClient.getStreamInputSplit(containerId)); if (j == 0 && isCache) { if (conf.getInt(XLearningConfiguration.XLEARNING_STREAM_EPOCH, XLearningConfiguration.DEFAULT_XLEARNING_STREAM_EPOCH) > 1) { gos.write(value.toString().getBytes()); gos.write("\n".getBytes()); gos.close(); } catch (Exception e) { LOG.warn("Exception in thread stdinRedirectThread");
public static byte[] gzip(byte[] data) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); GZIPOutputStream gzip = null; try { gzip = new GZIPOutputStream(bos); gzip.write(data); gzip.finish(); return bos.toByteArray(); } finally { if (gzip != null) { gzip.close(); } } }
byte[] chunk = new byte[65536]; if (comp != 0) { tgt = new GZIPOutputStream(bos); while ((len = bfobj.read(chunk)) >= 0) { tgt.write(chunk, 0, len); tgt.close(); bos = new BufferedOutputStream(new FileOutputStream(tmpFileBuffer, true)); } else {
public byte[] compress(byte[] org, boolean useGzip, int minGzSize) throws IOException { if (useGzip && org.length > minGzSize) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); GZIPOutputStream gos = new GZIPOutputStream(outputStream); gos.write(org); gos.finish(); gos.flush(); gos.close(); byte[] ret = outputStream.toByteArray(); return ret; } else { return org; } }
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(resp.getOutputStream()); gzipOutputStream.write("GZIP response".getBytes()); gzipOutputStream.close(); } else { resp.getPrintStream().append("agent=" + req.getValues("User-Agent").get(0));
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(); }