public CompressionOutputStream(final OutputStream outStream, final int bufferSize, final int level, final int strategy) { if (bufferSize < MIN_BUFFER_SIZE) { throw new IllegalArgumentException("Buffer size must be at least " + MIN_BUFFER_SIZE); } this.out = outStream; this.deflater = new Deflater(level); this.deflater.setStrategy(strategy); buffer = new byte[bufferSize]; compressed = new byte[bufferSize + 64]; }
@Override 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; }
@Override public void setOptions(String options) { if (options == null) { return; } try { StringTokenizer tokenizer = new StringTokenizer(options); while (tokenizer.hasMoreElements()) { String option = tokenizer.nextToken(); 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); } }
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; }
public void setOptions(String options) { if (options == null) { return; } try { StringTokenizer tokenizer = new StringTokenizer(options); while (tokenizer.hasMoreElements()) { String option = tokenizer.nextToken(); 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); } }
/** * Creates a {@link DataOutputStream} to write a chunk to a byte. * * @param x the chunk X coordinate within the region * @param z the chunk Z coordinate within the region * @return a {@link DataOutputStream}, backed by memory, that can prepare the chunk for writing * to disk. */ public DataOutputStream getChunkDataOutputStream(int x, int z) { checkBounds(x, z); Deflater deflater = new Deflater( COMPRESSION_ENABLED ? Deflater.BEST_SPEED : Deflater.NO_COMPRESSION); deflater.setStrategy(Deflater.HUFFMAN_ONLY); DeflaterOutputStream dos = new DeflaterOutputStream(new ChunkBuffer(x, z), deflater, 2048) { @Override public void close() throws IOException { super.close(); def.end(); } }; return new DataOutputStream(new BufferedOutputStream(dos)); }
def.setStrategy(strategy); } catch (IllegalArgumentException ex) { logger.log(Level.FINE, "Ignoring bad compression strategy", ex);
def.setStrategy(strategy); } catch (IllegalArgumentException ex) { logger.log(Level.FINE, "Ignoring bad compression strategy", ex);
public CompressorStreamDeflater(OutputStream os, int maxBlockLen, long totalLen, int deflaterCompLevel, int deflaterStrategy) { this(os, maxBlockLen, totalLen, new Deflater(deflaterCompLevel)); this.deflaterIsOwn = true; deflater.setStrategy(deflaterStrategy); }
/** * Sets the strategy that will be used. Valid values can be found in {@link Deflater}. Defaults to * {@link Deflater#DEFAULT_STRATEGY} * @param strategy the strategy to be used */ public void setStrategy(int strategy) { if (deflater != null && strategy != this.strategy) { deflater.reset(); deflater.setStrategy(strategy); } this.strategy = strategy; }
public DeflaterProcess(boolean nowrap) { deflater = new Deflater(Deflater.BEST_COMPRESSION,nowrap); deflater.setStrategy(Deflater.DEFAULT_STRATEGY); }
public DeflaterProcess(boolean nowrap) { deflater = new Deflater(Deflater.BEST_COMPRESSION,nowrap); deflater.setStrategy(Deflater.DEFAULT_STRATEGY); }
/** * Sets the strategy that will be used. Valid values can be found in {@link Deflater}. Defaults to * {@link Deflater#DEFAULT_STRATEGY} * @param strategy the strategy to be used */ public void setStrategy(int strategy) { if (deflater != null && strategy != this.strategy) { deflater.reset(); deflater.setStrategy(strategy); } this.strategy = strategy; }
public CompressionOutputStream(final OutputStream outStream, final int bufferSize, final int level, final int strategy) { if (bufferSize < MIN_BUFFER_SIZE) { throw new IllegalArgumentException("Buffer size must be at least " + MIN_BUFFER_SIZE); } this.out = outStream; this.deflater = new Deflater(level); this.deflater.setStrategy(strategy); buffer = new byte[bufferSize]; compressed = new byte[bufferSize + 64]; }
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); return compressed; }
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION); deflater.setStrategy(Deflater.DEFAULT_STRATEGY); byte[] compressed = new byte[10]; deflater.setInput(new byte[]{1}); deflater.finish(); int bytesCompressed = deflater.deflate(compressed); System.out.println("bytesCompressed=" + bytesCompressed + " " + Arrays.toString(compressed)); Inflater inflater = new Inflater(); inflater.setInput(compressed, 0, bytesCompressed); byte[] decompressed = new byte[2]; int byteDecompressed = inflater.inflate(decompressed); System.out.println("bytesInflated=" + byteDecompressed + " " + Arrays.toString(decompressed));
@Override public void setParams(int level, int strategy) { if (log.isDebugEnabled()) { log.debug("Changing deflate paramst to strategy {}, level {}", strategy, level); } deflater.setLevel(level); deflater.setStrategy(strategy); }
public ZlibDeflate(IRubyObject caller, int level, int win_bits, int memlevel, int strategy) { super(); // Zlib behavior: negative win_bits means no header and no checksum. flater = new Deflater(level, win_bits < 0); flater.setStrategy(strategy); collected = new org.jruby.util.ByteList(BASE_SIZE); runtime = caller.getRuntime(); }
private ByteArrayOutputStream deflate(PngByteArrayOutputStream inflatedImageData, int strategy, int compression) throws IOException { final ByteArrayOutputStream deflatedOut = new ByteArrayOutputStream(); final Deflater deflater = new Deflater(compression); deflater.setStrategy(strategy); try { final DeflaterOutputStream stream = new DeflaterOutputStream(deflatedOut, deflater); stream.write(inflatedImageData.get(), 0, inflatedImageData.len()); stream.close(); } finally { deflater.end(); } return deflatedOut; } }
@Override public OutputStream getOutputStream() throws IOException { if (out == null) { out = new ZippedBlockOutputStream(super.getOutputStream(), 1024); out.getCompressor().setStrategy(Deflater.DEFAULT_STRATEGY); out.getCompressor().setLevel(Deflater.BEST_COMPRESSION); } return out; } }