/// <exception cref="System.IO.IOException"/> public virtual void TestGzipCodecWrite(bool useNative) { // Create a gzipped file using a compressor from the CodecPool, // and try to read it back via the regular GZIPInputStream. // Use native libs per the parameter Configuration conf = new Configuration(); conf.SetBoolean(CommonConfigurationKeys.IoNativeLibAvailableKey, useNative); if (useNative) { if (!ZlibFactory.IsNativeZlibLoaded(conf)) { Log.Warn("testGzipCodecWrite skipped: native libs not loaded"); return; } } else { NUnit.Framework.Assert.IsFalse("ZlibFactory is using native libs against request" , ZlibFactory.IsNativeZlibLoaded(conf)); } // Ensure that the CodecPool has a BuiltInZlibDeflater in it. Compressor zlibCompressor = ZlibFactory.GetZlibCompressor(conf); NUnit.Framework.Assert.IsNotNull("zlibCompressor is null!", zlibCompressor); Assert.True("ZlibFactory returned unexpected deflator", useNative ? zlibCompressor is ZlibCompressor : zlibCompressor is BuiltInZlibDeflater); CodecPool.ReturnCompressor(zlibCompressor); // Create a GZIP text file via the Compressor interface. CompressionCodecFactory ccf = new CompressionCodecFactory(conf); CompressionCodec codec = ccf.GetCodec(new Path("foo.gz")); Assert.True("Codec for .gz file is not GzipCodec", codec is GzipCodec ); string msg = "This is the message we are going to compress."; string tmpDir = Runtime.GetProperty("test.build.data", "/tmp/"); string fileName = new Path(new Path(tmpDir), "testGzipCodecWrite.txt.gz").ToString (); BufferedWriter w = null; Compressor gzipCompressor = CodecPool.GetCompressor(codec); if (null != gzipCompressor) { // If it gives us back a Compressor, we should be able to use this // to write files we can then read back with Java's gzip tools. OutputStream os = new CompressorStream(new FileOutputStream(fileName), gzipCompressor ); w = new BufferedWriter(new OutputStreamWriter(os)); w.Write(msg); w.Close(); CodecPool.ReturnCompressor(gzipCompressor); VerifyGzipFile(fileName, msg); } // Create a gzip text file via codec.getOutputStream(). w = new BufferedWriter(new OutputStreamWriter(codec.CreateOutputStream(new FileOutputStream (fileName)))); w.Write(msg); w.Close(); VerifyGzipFile(fileName, msg); }
/// <summary>Allow children types to put a different type in here.</summary> /// <param name="out">the Deflater stream to use</param> protected internal GzipOutputStream(CompressorStream @out) : base(@out) { }