GZIPOutputStream finish - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for GZIPOutputStream finish method.

This code example shows how to use the following methods:finish
  public void flush() throws IOException {
    out.flush();
  } 
 
  public void finish() throws IOException {
    out.finish();
  } 
} 
7
CodeRank
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; 
		} 
	} 
 
7
CodeRank
This code example shows how to use the following methods:finish
  public void flush() throws IOException {
    out.flush();
  } 
 
  public void finish() throws IOException {
    out.finish();
  } 
} 
7
CodeRank
This code example shows how to use the following methods:finish
 
    public void close() throws IOException {
        if (closed) {
            throw new IOException("This output stream has already been closed");
        } 
        gzipstream.finish();
        closed = true;
    } 
 
    public void flush() throws IOException {
        if (closed) {
            throw new IOException("Cannot flush a closed output stream");
        } 
        gzipstream.flush();
    } 
 
    public void write(int b) throws IOException {
        if (closed) {
            throw new IOException("Cannot write to a closed output stream");
        } 
7
CodeRank
This code example shows how to use the following methods:finish
        super(delegate);
    } 
 
    public void serialize(Object instance, OutputStream out) throws IOException {
        if (isGzipEnabled()) { 
            GZIPOutputStream gzip = new GZIPOutputStream(out);
            delegate.serialize(instance, gzip);
            gzip.finish();
        } else { 
            delegate.serialize(instance, out);
        } 
    } 
 
    public <T> T deserialize(InputStream stream, Class<T> clazz) throws IOException {
        if (isGzipEnabled()) 
            stream = new GZIPInputStream(stream);
 
        return delegate.deserialize(stream, clazz);
    } 
} 
6
CodeRank
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; 
		} 
	} 
 
8
CodeRank
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
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) {
7
CodeRank
This code example shows how to use the following methods:close, flush, finish
    @Override 
    public <T> int serialize(T obj, Class<T> type, OutputStream out) throws IOException {
        out = new CountingOutputStream(out);
        GZIPOutputStream gzip = new GZIPOutputStream(out, getBufferSize());
        try { 
            getWrapped().serialize(obj, type, gzip);
            gzip.finish();
            gzip.flush();
        } finally { 
            if (isCloseEnabled()) { 
                gzip.close();
            } 
        } 
        return ((CountingOutputStream)out).getCount();
    } 
 
    /** 
     * {@inheritDoc} 
     */ 
    @Override 
7
CodeRank
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 {
8
CodeRank
finish Method Overview
Finishes writing compressed data to the output stream without closing the underlying stream.
See Code Examples for other Java 8 GZIPOutputStream Methods: