Java 8 GZIPOutputStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 GZIPOutputStream class.

This code example shows how to use the following methods:
			GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(gzJsFile.getFile()));
			FileCopyUtils.copy(jsFile.getInputStream(), out);
		} 
 
		if (gzFingerPrintedFile.getFile().createNewFile()) {
			GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(gzFingerPrintedFile.getFile()));
			FileCopyUtils.copy(fingerPrintedFile.getInputStream(), out);
		} 
 
		assertTrue(gzJsFile.exists());
		assertTrue(gzFingerPrintedFile.exists());
	} 
 
	@Before 
	public void setUp() { 
		Map<String, VersionStrategy> versionStrategyMap = new HashMap<>();
		versionStrategyMap.put("/**", new ContentVersionStrategy());
		VersionResourceResolver versionResolver = new VersionResourceResolver();
		versionResolver.setStrategyMap(versionStrategyMap);
 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: finish
    } 
 
    public static InputStream compressGzip(String contentEncoding, InputStream in) throws IOException {
        if (isGzip(contentEncoding)) {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            GZIPOutputStream gzip = new GZIPOutputStream(os);
            try { 
                IOHelper.copy(in, gzip);
                gzip.finish();
                return new ByteArrayInputStream(os.toByteArray());
            } finally { 
                IOHelper.close(gzip, "gzip");
                IOHelper.close(os, "byte array output stream");
            } 
        } else { 
            return in;
        } 
    } 
 
    public static InputStream compressGzip(String contentEncoding, byte[] data) throws IOException {
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
  private HttpServletResponse response;
  private GZIPOutputStream out;
 
  public GZIPResponseStream(HttpServletResponse response) throws IOException {
    this.response = response;
    this.out = new GZIPOutputStream(response.getOutputStream());
    response.addHeader("Content-Encoding", "gzip");
  } 
 
  public void resetBuffer() { 
    if (out != null && !response.isCommitted()) {
      response.setHeader("Content-Encoding", null);
    } 
    out = null;
  } 
 
  @Override 
  public void write(int b) throws IOException {
    out.write(b);
  } 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: finish
    } 
 
    public void compressTo(InputStream in, OutputStream out) throws CompressException {
        GZIPOutputStream gzipOut = null;
        try { 
            gzipOut = new GZIPOutputStream(out);
            NioUtils.copy(in, gzipOut);
            gzipOut.finish(); //需要使用finish
        } catch (Exception e) {
            throw new CompressException("gzip_compress_error", e);
        } 
    } 
 
    public void decompressTo(InputStream in, OutputStream out) throws CompressException {
        GZIPInputStream gzipin = null;
        try { 
            gzipin = new GZIPInputStream(in);
            NioUtils.copy(gzipin, out);
            out.flush();
        } catch (Exception e) {
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
        @edu.umd.cs.findbugs.annotations.SuppressWarnings({ "OS_OPEN_STREAM" }) 
        public void write(final ObjectDataOutput out, final Object obj) throws IOException {
            final ObjectOutputStream objectOutputStream;
            final OutputStream outputStream = (OutputStream) out;
            if (gzipEnabled) {
                objectOutputStream = new ObjectOutputStream(new GZIPOutputStream(outputStream));
            } else { 
                objectOutputStream = new ObjectOutputStream(outputStream);
            } 
            if (shared) {
                objectOutputStream.writeObject(obj);
            } else { 
                objectOutputStream.writeUnshared(obj);
            } 
            // Force flush if not yet written due to internal behavior if pos < 1024 
            objectOutputStream.flush();
        } 
    } 
 
    public static final class EnumSerializer extends SingletonSerializer<Enum> {
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
  private void doGzipResponse(final HttpServletRequest req, final HttpServletResponse response, final FilterChain chain)
      throws IOException, ServletException {
    LOG.debug("Applying gzip on resource: " + req.getRequestURI());
    response.setHeader(HttpHeader.CONTENT_ENCODING.toString(), "gzip");
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final CountingOutputStream countingStream = new CountingOutputStream(new GZIPOutputStream(new BufferedOutputStream(
        baos)));
    // final GZIPOutputStream gzout = new GZIPOutputStream(new BufferedOutputStream(baos)); 
    // Perform gzip operation in-memory before sending response 
    final HttpServletResponseWrapper wrappedResponse = new RedirectedStreamServletResponseWrapper(countingStream,
        response);
    chain.doFilter(req, wrappedResponse);
    // close underlying stream 
    countingStream.close();
    response.setContentLength(countingStream.getCount());
    // avoid NO CONTENT error thrown by jetty when gzipping empty response 
    if (countingStream.getCount() > 0) {
      IOUtils.write(baos.toByteArray(), response.getOutputStream());
    } 
  } 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
  private HttpServletResponse response;
  private GZIPOutputStream out;
 
  public GZIPResponseStream(HttpServletResponse response) throws IOException {
    this.response = response;
    this.out = new GZIPOutputStream(response.getOutputStream());
    response.addHeader("Content-Encoding", "gzip");
  } 
 
  public void resetBuffer() { 
    if (out != null && !response.isCommitted()) {
      response.setHeader("Content-Encoding", null);
    } 
    out = null;
  } 
 
  @Override 
  public void write(int b) throws IOException {
    out.write(b);
  } 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: close, finish, write
	 
	public static NSData gzipByteArrayAsNSData(byte[] input, int offset, int length) {
		try { 
			ERXRefByteArrayOutputStream bos = new ERXRefByteArrayOutputStream(length);
			if (input != null) {
				GZIPOutputStream out = new GZIPOutputStream(bos);
	 
				out.write(input, offset, length);
	 
				out.finish();
				out.close();
			} 
			return bos.toNSData();
		} 
		catch (IOException e) {
			log.error("Failed to gzip byte array.", e);
			return null; 
		} 
	} 
 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: close, finish, write
	 
	public static NSData gzipByteArrayAsNSData(byte[] input, int offset, int length) {
		try { 
			ERXRefByteArrayOutputStream bos = new ERXRefByteArrayOutputStream(length);
			if (input != null) {
				GZIPOutputStream out = new GZIPOutputStream(bos);
	 
				out.write(input, offset, length);
	 
				out.finish();
				out.close();
			} 
			return bos.toNSData();
		} 
		catch (IOException e) {
			log.error("Failed to gzip byte array.", e);
			return null; 
		} 
	} 
 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: flush, finish, write
		is = new BufferedInputStream(is, 32768);
		GZIPOutputStream gos = null;
		os = new BufferedOutputStream(os, 32768);
		CountedOutputStream cos = new CountedOutputStream(os);
		try { 
			gos = new GZIPOutputStream(cos);
			long read = 0;
			// Bigger input buffer, so can compress all at once. 
			// Won't hurt on I/O either, although most OSs will only return a page at a time. 
			byte[] buffer = new byte[32768];
			while(true) { 
				int l = (int) Math.min(buffer.length, maxReadLength - read);
				int x = l == 0 ? -1 : is.read(buffer, 0, l);
				if(x <= -1) break;
				if(x == 0) throw new IOException("Returned zero from read()");
				gos.write(buffer, 0, x);
				read += x;
				if(cos.written() > maxWriteLength)
					throw new CompressionOutputSizeException(); 
			} 

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 GZIPOutputStream Questions & Answers:

See Code Examples for Java 8 GZIPOutputStream Methods: