Java 8 DeflaterOutputStream - 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 DeflaterOutputStream class.

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, putNextEntry, write, close
            manifest.write(manOut);
            byte[] manBytes = manOut.toByteArray();
            File file = File.createTempFile(
                    Support_PlatformFile.getNewPlatformFile("hyts_manifest1", 
                            ""), ".jar"); 
            JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(
                    file.getAbsolutePath()));
            ZipEntry entry = new ZipEntry("META-INF/");
            entry.setSize(0);
            jarOut.putNextEntry(entry);
            entry = new ZipEntry(JarFile.MANIFEST_NAME);
            entry.setSize(manBytes.length);
            jarOut.putNextEntry(entry);
            jarOut.write(manBytes);
            entry = new ZipEntry("myfile");
            entry.setSize(1);
            jarOut.putNextEntry(entry);
            jarOut.write(65);
            jarOut.close();
            JarFile jar = new JarFile(file.getAbsolutePath(), false);

7
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
			throw ERT.badarg(bin);
		} 
		 
		Deflater defl = new Deflater();
		BARR bos = new BARR();
		DeflaterOutputStream dos = new DeflaterOutputStream(bos, defl);
		 
		try { 
			b.writeTo(dos);
			dos.close();
		} catch (IOException e) {
			throw new InternalError("should not happen");
		} 
		 
		return bos.asBinary();		
	} 
	 
	static private class BARR extends ByteArrayOutputStream {
		EBinary asBinary() { 
			return new EBinary(super.buf, 0, super.count);
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: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:
  public final void write(DataOutput out) throws IOException {
    if (compressed == null) {
      ByteArrayOutputStream deflated = new ByteArrayOutputStream();
      Deflater deflater = new Deflater(Deflater.BEST_SPEED);
      DataOutputStream dout =
        new DataOutputStream(new DeflaterOutputStream(deflated, deflater));
      writeCompressed(dout);
      dout.close();
      deflater.end();
      compressed = deflated.toByteArray();
    } 
    out.writeInt(compressed.length);
    out.write(compressed);
  } 
 
  /** Subclasses implement this instead of {@link #write(DataOutput)}. */ 
  protected abstract void writeCompressed(DataOutput out) throws IOException;
 
} 
7
CodeRank
This code example shows how to use the following methods:close, flush, write
    if (srcLength - srcOffset == 0) {
      return 0; 
    } 
    try { 
      ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(srcLength - srcOffset);
      GZIPOutputStream gzip = new GZIPOutputStream(bytesOut);
      gzip.write(src, srcOffset, srcLength);
      gzip.flush();
      gzip.close();
      byte[] compressed = bytesOut.toByteArray();
      System.arraycopy(compressed, 0, dst, dstOff, compressed.length);
      return compressed.length;
    } catch (IOException e) {
      throw new RuntimeException("Unexpected IOException while compressing!", e);
    } 
  } 
 
  @Override 
  public int decompress(byte[] src, int srcOffset, int srcLength, byte[] dst, int dstOff) {
    if (srcLength - srcOffset == 0) {
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:close

Related Java 8 DeflaterOutputStream Questions & Answers:

See Code Examples for Java 8 DeflaterOutputStream Methods: