Java Code Examples for java.util.zip.Deflater#setDictionary()

The following examples show how to use java.util.zip.Deflater#setDictionary() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InflaterTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
private static byte[] deflate(byte[] input, byte[] dictionary) {
    Deflater deflater = new Deflater();
    ByteArrayOutputStream deflatedBytes = new ByteArrayOutputStream();
    try {
        if (dictionary != null) {
            deflater.setDictionary(dictionary);
        }
        deflater.setInput(input);
        deflater.finish();
        byte[] buf = new byte[8];
        while (!deflater.finished()) {
            int byteCount = deflater.deflate(buf);
            deflatedBytes.write(buf, 0, byteCount);
        }
    } finally {
        deflater.end();
    }
    return deflatedBytes.toByteArray();
}
 
Example 2
Source File: Spdy3.java    From crosswalk-cordova-android with Apache License 2.0 5 votes vote down vote up
Writer(OutputStream out, boolean client) {
  this.out = new DataOutputStream(out);
  this.client = client;

  Deflater deflater = new Deflater();
  deflater.setDictionary(DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 3
Source File: SpdyHeaderBlockZlibEncoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
SpdyHeaderBlockZlibEncoder(SpdyVersion spdyVersion, int compressionLevel) {
    super(spdyVersion);
    if (compressionLevel < 0 || compressionLevel > 9) {
        throw new IllegalArgumentException(
                "compressionLevel: " + compressionLevel + " (expected: 0-9)");
    }
    compressor = new Deflater(compressionLevel);
    compressor.setDictionary(SPDY_DICT);
}
 
Example 4
Source File: SpdyWriter.java    From phonegap-plugin-loading-spinner with Apache License 2.0 5 votes vote down vote up
SpdyWriter(OutputStream out) {
  this.out = new DataOutputStream(out);

  Deflater deflater = new Deflater();
  deflater.setDictionary(SpdyReader.DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 5
Source File: Spdy3.java    From wildfly-samples with MIT License 5 votes vote down vote up
Writer(OutputStream out, boolean client) {
  this.out = new DataOutputStream(out);
  this.client = client;

  Deflater deflater = new Deflater();
  deflater.setDictionary(DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 6
Source File: SpdyWriter.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
SpdyWriter(OutputStream out) {
  this.out = new DataOutputStream(out);

  Deflater deflater = new Deflater();
  deflater.setDictionary(SpdyReader.DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 7
Source File: Spdy3.java    From CordovaYoutubeVideoPlayer with MIT License 5 votes vote down vote up
Writer(OutputStream out, boolean client) {
  this.out = new DataOutputStream(out);
  this.client = client;

  Deflater deflater = new Deflater();
  deflater.setDictionary(DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 8
Source File: Spdy3.java    From phonegapbootcampsite with MIT License 5 votes vote down vote up
Writer(OutputStream out, boolean client) {
  this.out = new DataOutputStream(out);
  this.client = client;

  Deflater deflater = new Deflater();
  deflater.setDictionary(DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 9
Source File: Spdy3.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
Writer(OutputStream out, boolean client) {
  this.out = new DataOutputStream(out);
  this.client = client;

  Deflater deflater = new Deflater();
  deflater.setDictionary(DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 10
Source File: Spdy3.java    From reader with MIT License 5 votes vote down vote up
Writer(OutputStream out, boolean client) {
  this.out = new DataOutputStream(out);
  this.client = client;

  Deflater deflater = new Deflater();
  deflater.setDictionary(DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 11
Source File: Spdy3.java    From reader with MIT License 5 votes vote down vote up
Writer(OutputStream out, boolean client) {
  this.out = new DataOutputStream(out);
  this.client = client;

  Deflater deflater = new Deflater();
  deflater.setDictionary(DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 12
Source File: SpdyHeaderBlockZlibEncoder.java    From whiskey with Apache License 2.0 5 votes vote down vote up
SpdyHeaderBlockZlibEncoder(SpdyVersion spdyVersion, int compressionLevel) {
    super(spdyVersion);
    if (compressionLevel < 0 || compressionLevel > 9) {
        throw new IllegalArgumentException(
                "compressionLevel: " + compressionLevel + " (expected: 0-9)");
    }
    compressor = new Deflater(compressionLevel);
    compressor.setDictionary(SPDY_DICT);
}
 
Example 13
Source File: Spdy3.java    From bluemix-parking-meter with MIT License 5 votes vote down vote up
Writer(OutputStream out, boolean client) {
  this.out = new DataOutputStream(out);
  this.client = client;

  Deflater deflater = new Deflater();
  deflater.setDictionary(DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 14
Source File: Spdy3.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
Writer(OutputStream out, boolean client) {
    this.out = new DataOutputStream(out);
    this.client = client;

    Deflater deflater = new Deflater();
    deflater.setDictionary(DICTIONARY);
    nameValueBlockBuffer = new ByteArrayOutputStream();
    nameValueBlockOut = new DataOutputStream(Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 15
Source File: Spdy3.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
Writer(OutputStream out, boolean client) {
  this.out = new DataOutputStream(out);
  this.client = client;

  Deflater deflater = new Deflater();
  deflater.setDictionary(DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 16
Source File: SpdyHeaderBlockZlibEncoder.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
SpdyHeaderBlockZlibEncoder(SpdyVersion spdyVersion, int compressionLevel) {
    super(spdyVersion);
    if (compressionLevel < 0 || compressionLevel > 9) {
        throw new IllegalArgumentException(
                "compressionLevel: " + compressionLevel + " (expected: 0-9)");
    }
    compressor = new Deflater(compressionLevel);
    compressor.setDictionary(SPDY_DICT);
}
 
Example 17
Source File: Spdy3.java    From L.TileLayer.Cordova with MIT License 5 votes vote down vote up
Writer(OutputStream out, boolean client) {
  this.out = new DataOutputStream(out);
  this.client = client;

  Deflater deflater = new Deflater();
  deflater.setDictionary(DICTIONARY);
  nameValueBlockBuffer = new ByteArrayOutputStream();
  nameValueBlockOut = new DataOutputStream(
      Platform.get().newDeflaterOutputStream(nameValueBlockBuffer, deflater, true));
}
 
Example 18
Source File: JdkZlibEncoder.java    From netty4.0.27Learn with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new zlib encoder with the specified {@code compressionLevel}
 * and the specified preset dictionary.  The wrapper is always
 * {@link ZlibWrapper#ZLIB} because it is the only format that supports
 * the preset dictionary.
 *
 * @param compressionLevel
 *        {@code 1} yields the fastest compression and {@code 9} yields the
 *        best compression.  {@code 0} means no compression.  The default
 *        compression level is {@code 6}.
 * @param dictionary  the preset dictionary
 *
 * @throws CompressionException if failed to initialize zlib
 */
public JdkZlibEncoder(int compressionLevel, byte[] dictionary) {
    if (compressionLevel < 0 || compressionLevel > 9) {
        throw new IllegalArgumentException(
                "compressionLevel: " + compressionLevel + " (expected: 0-9)");
    }
    if (dictionary == null) {
        throw new NullPointerException("dictionary");
    }

    wrapper = ZlibWrapper.ZLIB;
    deflater = new Deflater(compressionLevel);
    deflater.setDictionary(dictionary);
}
 
Example 19
Source File: JdkZlibEncoder.java    From netty-4.1.22 with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new zlib encoder with the specified {@code compressionLevel}
 * and the specified preset dictionary.  The wrapper is always
 * {@link ZlibWrapper#ZLIB} because it is the only format that supports
 * the preset dictionary.
 *
 * @param compressionLevel
 *        {@code 1} yields the fastest compression and {@code 9} yields the
 *        best compression.  {@code 0} means no compression.  The default
 *        compression level is {@code 6}.
 * @param dictionary  the preset dictionary
 *
 * @throws CompressionException if failed to initialize zlib
 * 使用指定的压缩级别和指定的预设置字典创建一个新的zlib编码器。包装器总是ZlibWrapper。ZLIB是因为它是唯一支持预设字典的格式。
 */
public JdkZlibEncoder(int compressionLevel, byte[] dictionary) {
    if (compressionLevel < 0 || compressionLevel > 9) {
        throw new IllegalArgumentException(
                "compressionLevel: " + compressionLevel + " (expected: 0-9)");
    }
    if (dictionary == null) {
        throw new NullPointerException("dictionary");
    }

    wrapper = ZlibWrapper.ZLIB;
    deflater = new Deflater(compressionLevel);
    deflater.setDictionary(dictionary);
}