Exemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        private static void CodecTestWithNOCompression(Configuration conf, string codecClass
                                                       )
        {
            // Create a compressor with NO_COMPRESSION and make sure that
            // output is not compressed by comparing the size with the
            // original input
            CompressionCodec codec = null;

            ZlibFactory.SetCompressionLevel(conf, ZlibCompressor.CompressionLevel.NoCompression
                                            );
            try
            {
                codec = (CompressionCodec)ReflectionUtils.NewInstance(conf.GetClassByName(codecClass
                                                                                          ), conf);
            }
            catch (TypeLoadException)
            {
                throw new IOException("Illegal codec!");
            }
            Compressor c = codec.CreateCompressor();
            // ensure same compressor placed earlier
            ByteArrayOutputStream   bos = new ByteArrayOutputStream();
            CompressionOutputStream cos = null;

            // write trivially compressable data
            byte[] b = new byte[1 << 15];
            Arrays.Fill(b, unchecked ((byte)43));
            try
            {
                cos = codec.CreateOutputStream(bos, c);
                cos.Write(b);
            }
            finally
            {
                if (cos != null)
                {
                    cos.Close();
                }
            }
            byte[] outbytes = bos.ToByteArray();
            // verify data were not compressed
            Assert.True("Compressed bytes contrary to configuration(NO_COMPRESSION)"
                        , outbytes.Length >= b.Length);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get a
        /// <see cref="Compressor"/>
        /// for the given
        /// <see cref="CompressionCodec"/>
        /// from the
        /// pool or a new one.
        /// </summary>
        /// <param name="codec">
        /// the <code>CompressionCodec</code> for which to get the
        /// <code>Compressor</code>
        /// </param>
        /// <param name="conf">the <code>Configuration</code> object which contains confs for creating or reinit the compressor
        ///     </param>
        /// <returns>
        /// <code>Compressor</code> for the given
        /// <code>CompressionCodec</code> from the pool or a new one
        /// </returns>
        public static Compressor GetCompressor(CompressionCodec codec, Configuration conf
                                               )
        {
            Compressor compressor = Borrow(compressorPool, codec.GetCompressorType());

            if (compressor == null)
            {
                compressor = codec.CreateCompressor();
                Log.Info("Got brand-new compressor [" + codec.GetDefaultExtension() + "]");
            }
            else
            {
                compressor.Reinit(conf);
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Got recycled compressor");
                }
            }
            UpdateLeaseCount(compressorCounts, compressor, 1);
            return(compressor);
        }