Package java.util.zip

Examples of java.util.zip.Deflater


    public static byte[] zlibCompress(String what) {
        byte[] input = what.getBytes(StandardCharsets.UTF_8);

        // Compress the bytes
        byte[] output = new byte[4096];
        Deflater compresser = new Deflater();
        compresser.setInput(input);
        compresser.finish();
        compresser.deflate(output);

        return output;
    }
View Full Code Here


          root.updateDirectoryEntry(buildName, 0, nextEntry);
        }
        else
        {
          final ByteArrayOutputStream bos = new ByteArrayOutputStream();
          final Deflater def = new Deflater(nextEntry.getMethod());
          try
          {
            final DeflaterOutputStream dos = new DeflaterOutputStream(bos, def);
            try
            {
              IOUtils.getInstance().copyStreams(zipIn, dos);
              dos.flush();
            }
            finally
            {
              dos.close();
            }
          }
          finally
          {
            def.end();
          }

          root.updateEntry(buildName, 0, nextEntry, bos.toByteArray());
        }
View Full Code Here

    {
      throw new NullPointerException();
    }
    this.item = item;
    this.outputStream = new ByteArrayOutputStream();
    this.deflater = new Deflater(RepositoryUtilities.getZipLevel(item));
    this.deflaterOutputStream = new DeflaterOutputStream(outputStream, deflater);
    this.crc32 = new CRC32();
    this.size = 0;
  }
View Full Code Here

          root.updateDirectoryEntry(buildName, 0, nextEntry);
        }
        else
        {
          final ByteArrayOutputStream bos = new ByteArrayOutputStream();
          final Deflater def = new Deflater(nextEntry.getMethod());
          try
          {
            final DeflaterOutputStream dos = new DeflaterOutputStream(bos, def);
            try
            {
              IOUtils.getInstance().copyStreams(zipIn, dos);
              dos.flush();
            }
            finally
            {
              dos.close();
            }
          }
          finally
          {
            def.end();
          }
          root.updateEntry(buildName, 0, nextEntry, bos.toByteArray());
        }

        zipIn.closeEntry();
View Full Code Here

     * Creates a new ZIP OutputStream filtering the underlying stream.
     *
     * @since 1.1
     */
    public ZipOutputStream(OutputStream out) {
        super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
    }
View Full Code Here

                if ("level".equals(option) || "l".equals(option)) {
                    level = Integer.parseInt(tokenizer.nextToken());
                } else if ("strategy".equals(option) || "s".equals(option)) {
                    strategy = Integer.parseInt(tokenizer.nextToken());
                }
                Deflater deflater = new Deflater(level);
                deflater.setStrategy(strategy);
            }
        } catch (Exception e) {
            throw DbException.get(ErrorCode.UNSUPPORTED_COMPRESSION_OPTIONS_1, options);
        }
    }
View Full Code Here

            throw DbException.get(ErrorCode.UNSUPPORTED_COMPRESSION_OPTIONS_1, options);
        }
    }

    public int compress(byte[] in, int inLen, byte[] out, int outPos) {
        Deflater deflater = new Deflater(level);
        deflater.setStrategy(strategy);
        deflater.setInput(in, 0, inLen);
        deflater.finish();
        int compressed = deflater.deflate(out, outPos, out.length - outPos);
        while (compressed == 0) {
            // the compressed length is 0, meaning compression didn't work
            // (sounds like a JDK bug)
            // try again, using the default strategy and compression level
            strategy = Deflater.DEFAULT_STRATEGY;
            level = Deflater.DEFAULT_COMPRESSION;
            return compress(in, inLen, out, outPos);
        }
        deflater.end();
        return outPos + compressed;
    }
View Full Code Here

     * @return compressed string representation.
     */
    public static synchronized String compress( final String data ) {

        ByteArrayOutputStream byteOut = new ByteArrayOutputStream( 512 );
        Deflater deflater = new Deflater();
        DeflaterOutputStream oStream = new DeflaterOutputStream( byteOut, deflater );

        try {
            oStream.write( data.getBytes( CONVERTER_UTF8 ) );
            oStream.flush();
View Full Code Here

            out.close();
        } else if (response.getHeader("content-encoding") != null &&
                response.getHeader("content-encoding").equals("deflate")) {
            // Deflate the data
            isEncoded = true;
            Deflater compressor = new Deflater();
            compressor.setInput(content.getBytes());
            compressor.finish();

            byte[] buffer = new byte[1024];
            while (!compressor.finished()) {
                int count = compressor.deflate(buffer);
                out.write(buffer, 0, count);
            }
            out.close();
            compressor.end();
        }


        // don't do this if we got a HTTP 304 since there is no data to send back
        if (response.getStatus() != HttpServletResponse.SC_NOT_MODIFIED) {
View Full Code Here


    public void init() throws Exception {
        deflater_pool=new ArrayBlockingQueue<Deflater>(pool_size);
        for(int i=0; i < pool_size; i++)
            deflater_pool.add(new Deflater(compression_level));
        inflater_pool=new ArrayBlockingQueue<Inflater>(pool_size);
        for(int i=0; i < pool_size; i++)
            inflater_pool.add(new Inflater());
    }
View Full Code Here

TOP

Related Classes of java.util.zip.Deflater

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.