Java Code Examples for org.apache.hadoop.io.compress.zlib.ZlibFactory#setCompressionStrategy()

The following examples show how to use org.apache.hadoop.io.compress.zlib.ZlibFactory#setCompressionStrategy() . 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: TestCodec.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testGzipCodecWithParam() throws IOException {
  Configuration conf = new Configuration(this.conf);
  ZlibFactory.setCompressionLevel(conf, CompressionLevel.BEST_COMPRESSION);
  ZlibFactory.setCompressionStrategy(conf, CompressionStrategy.HUFFMAN_ONLY);
  codecTest(conf, seed, 0, "org.apache.hadoop.io.compress.GzipCodec");
  codecTest(conf, seed, count, "org.apache.hadoop.io.compress.GzipCodec");
}
 
Example 2
Source File: TestCodec.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static void gzipReinitTest(Configuration conf, CompressionCodec codec)
    throws IOException {
  // Add codec to cache
  ZlibFactory.setCompressionLevel(conf, CompressionLevel.BEST_COMPRESSION);
  ZlibFactory.setCompressionStrategy(conf,
      CompressionStrategy.DEFAULT_STRATEGY);
  Compressor c1 = CodecPool.getCompressor(codec);
  CodecPool.returnCompressor(c1);
  // reset compressor's compression level to perform no compression
  ZlibFactory.setCompressionLevel(conf, CompressionLevel.NO_COMPRESSION);
  Compressor c2 = CodecPool.getCompressor(codec, conf);
  // ensure same compressor placed earlier
  assertTrue("Got mismatched ZlibCompressor", c1 == c2);
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  CompressionOutputStream cos = null;
  // write trivially compressable data
  byte[] b = new byte[1 << 15];
  Arrays.fill(b, (byte) 43);
  try {
    cos = codec.createOutputStream(bos, c2);
    cos.write(b);
  } finally {
    if (cos != null) {
      cos.close();
    }
    CodecPool.returnCompressor(c2);
  }
  byte[] outbytes = bos.toByteArray();
  // verify data were not compressed
  assertTrue("Compressed bytes contrary to configuration",
             outbytes.length >= b.length);
}
 
Example 3
Source File: TestCodec.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testGzipCodecWithParam() throws IOException {
  Configuration conf = new Configuration(this.conf);
  ZlibFactory.setCompressionLevel(conf, CompressionLevel.BEST_COMPRESSION);
  ZlibFactory.setCompressionStrategy(conf, CompressionStrategy.HUFFMAN_ONLY);
  codecTest(conf, seed, 0, "org.apache.hadoop.io.compress.GzipCodec");
  codecTest(conf, seed, count, "org.apache.hadoop.io.compress.GzipCodec");
}
 
Example 4
Source File: TestCodec.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static void gzipReinitTest(Configuration conf, CompressionCodec codec)
    throws IOException {
  // Add codec to cache
  ZlibFactory.setCompressionLevel(conf, CompressionLevel.BEST_COMPRESSION);
  ZlibFactory.setCompressionStrategy(conf,
      CompressionStrategy.DEFAULT_STRATEGY);
  Compressor c1 = CodecPool.getCompressor(codec);
  CodecPool.returnCompressor(c1);
  // reset compressor's compression level to perform no compression
  ZlibFactory.setCompressionLevel(conf, CompressionLevel.NO_COMPRESSION);
  Compressor c2 = CodecPool.getCompressor(codec, conf);
  // ensure same compressor placed earlier
  assertTrue("Got mismatched ZlibCompressor", c1 == c2);
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  CompressionOutputStream cos = null;
  // write trivially compressable data
  byte[] b = new byte[1 << 15];
  Arrays.fill(b, (byte) 43);
  try {
    cos = codec.createOutputStream(bos, c2);
    cos.write(b);
  } finally {
    if (cos != null) {
      cos.close();
    }
    CodecPool.returnCompressor(c2);
  }
  byte[] outbytes = bos.toByteArray();
  // verify data were not compressed
  assertTrue("Compressed bytes contrary to configuration",
             outbytes.length >= b.length);
}