DeflaterOutputStream close - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:close, finish, write
	} 
 
	public static byte[] deflateByteArray(byte[] input) {
		try { 
			ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
			DeflaterOutputStream out = new DeflaterOutputStream(bos);
 
			out.write(input, 0, input.length);
 
			out.finish();
			out.close();
 
			byte[] compressedData = bos.toByteArray();
			return compressedData;
		} 
		catch (IOException e) {
			return null; 
		} 
	} 
 
8
CodeRank
This code example shows how to use the following methods:write, close, finish
This code example shows how to use the following methods:close, finish, write
	} 
 
	public static byte[] deflateByteArray(byte[] input) {
		try { 
			ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
			DeflaterOutputStream out = new DeflaterOutputStream(bos);
 
			out.write(input, 0, input.length);
 
			out.finish();
			out.close();
 
			byte[] compressedData = bos.toByteArray();
			return compressedData;
		} 
		catch (IOException e) {
			return null; 
		} 
	} 
 
7
CodeRank
This code example shows how to use the following methods:write, close
     */ 
    public byte[] zip(String str) {
        GZIPOutputStream zipStream = null;
        try { 
            ByteArrayOutputStream targetStream = new ByteArrayOutputStream();
            zipStream = new GZIPOutputStream(targetStream);
            zipStream.write(str.getBytes());
            zipStream.close();
            byte[] zipped = targetStream.toByteArray();
            targetStream.close();
            return zipped;
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        } finally { 
            try { 
                if (zipStream != null) {
                    zipStream.close();
                } 
            } catch (IOException ex) {
                throw new RuntimeException(ex);

7
CodeRank
This code example shows how to use the following methods:close
This code example shows how to use the following methods:close, write
        if (closed)
            throw new IOException("This output stream has already been closed");
 
        if (gzipstream != null) {
            flushToGZip(); 
            gzipstream.close();
            gzipstream = null;
        } else { 
            if (bufferCount > 0) {
                if (debug > 2) {
                    System.out.print("output.write(");
                    System.out.write(buffer, 0, bufferCount);
                    System.out.println(")");
                } 
                output.write(buffer, 0, bufferCount);
                bufferCount = 0;
            } 
        } 
 
        output.close();

6
CodeRank
This code example shows how to use the following methods:write, close
	public void setGzip_len(Integer gzip_len) {
		this.gzip_len = gzip_len;
	} 
	private static ByteArrayOutputStream writeStream(String content, int nMaxLen) throws IOException {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		GZIPOutputStream gzip = new GZIPOutputStream(out);
		if (content.length() > nMaxLen) {
			gzip.write(content.getBytes(), 0, nMaxLen); // (first 100KB - or whatever's configured - only)
		} 
		else { 
			gzip.write(content.getBytes());
		} 
		gzip.close();
		return out;
	} 
 
	public void setGzip_raw_content(byte[] gzip_raw_content) {
		this.gzip_raw_content = gzip_raw_content;
	} 
 
6
CodeRank
This code example shows how to use the following methods:write, close
	 * @return ·µ»ØѹËõºóµÄÊý¾Ý 
	 * @throws IOException 
	 */ 
	public static byte[] makeAsByteArray(byte[] data) throws IOException {
		ByteArrayOutputStream out = new ByteArrayOutputStream(data.length);
		GZIPOutputStream zipOut = new GZIPOutputStream(out, Math.max(data.length / 10, 512));
		zipOut.write(data);
		zipOut.close();
		return out.toByteArray();
	} 
 
	/** 
	 * ½«dataÒÔgzip·½Ê½Ñ¹Ëõ£¬²¢·µ»ØÒ»¸ö¿É¶ÁÈ¡µÄInputStream 
	 *  
	 * @param data 
	 * @return ·µ»Ø¿É¶ÁµÄInputStream 
	 * @throws IOException 
	 */ 
	public static InputStream makeAsInputStream(byte[] data) throws IOException {
		return new ByteArrayInputStream(makeAsByteArray(data));
6
CodeRank
This code example shows how to use the following methods:write, close
 
    @Override 
    protected byte[] doCompress(byte[] plain) throws IOException {
 
        @Cleanup ByteArrayOutputStream bos = new ByteArrayOutputStream();
        @Cleanup GZIPOutputStream gzip = new GZIPOutputStream(bos);
 
        gzip.write(plain);
        gzip.close();
 
        return bos.toByteArray();
 
    } 
 
    @Override 
    protected byte[] doDecompress(byte[] compressed) throws IOException {
 
        @Cleanup 
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        @Cleanup 
6
CodeRank
This code example shows how to use the following methods:close
        } 
 
        @Override 
        public void close() throws IOException { 
            TestOutputStream.closeCalled = true;
            gzos.close();
        } 
 
        @Override 
        public void flush() throws IOException { 
            if (!closeCalled) {
                flushCalledBeforeClose = true;
            } 
            gzos.flush();
        } 
    } 
 
    @Path("resource") 
    public static class TestResource { 
        @GET 
6
CodeRank

Related DeflaterOutputStream close Questions & Answers:

close Method Overview
Writes remaining compressed data to the output stream and closes the underlying stream.
See Code Examples for other Java 8 DeflaterOutputStream Methods: