Ejemplo n.º 1
0
                internal override void AssertCompression(string name, Compressor compressor, Decompressor
                                                         decompressor, byte[] originalRawData)
                {
                    byte[] buf = null;
                    ByteArrayInputStream    bytesIn = null;
                    BlockDecompressorStream blockDecompressorStream = null;
                    ByteArrayOutputStream   bytesOut = new ByteArrayOutputStream();

                    // close without write
                    try
                    {
                        compressor.Reset();
                        // decompressor.end();
                        BlockCompressorStream blockCompressorStream = new BlockCompressorStream(bytesOut,
                                                                                                compressor, 1024, 0);
                        blockCompressorStream.Close();
                        // check compressed output
                        buf = bytesOut.ToByteArray();
                        int emSize = this.emptySize[compressor.GetType()];
                        Assert.Equal(this.joiner.Join(name, "empty stream compressed output size != "
                                                      + emSize), emSize, buf.Length);
                        // use compressed output as input for decompression
                        bytesIn = new ByteArrayInputStream(buf);
                        // create decompression stream
                        blockDecompressorStream = new BlockDecompressorStream(bytesIn, decompressor, 1024
                                                                              );
                        // no byte is available because stream was closed
                        Assert.Equal(this.joiner.Join(name, " return value is not -1")
                                     , -1, blockDecompressorStream.Read());
                    }
                    catch (IOException e)
                    {
                        NUnit.Framework.Assert.Fail(this.joiner.Join(name, e.Message));
                    }
                    finally
                    {
                        if (blockDecompressorStream != null)
                        {
                            try
                            {
                                bytesOut.Close();
                                blockDecompressorStream.Close();
                                bytesIn.Close();
                                blockDecompressorStream.Close();
                            }
                            catch (IOException)
                            {
                            }
                        }
                    }
                }
Ejemplo n.º 2
0
        public virtual void TestCompressorDecompressorEmptyStreamLogic()
        {
            ByteArrayInputStream  bytesIn  = null;
            ByteArrayOutputStream bytesOut = null;

            byte[] buf = null;
            BlockDecompressorStream blockDecompressorStream = null;

            try
            {
                // compress empty stream
                bytesOut = new ByteArrayOutputStream();
                BlockCompressorStream blockCompressorStream = new BlockCompressorStream(bytesOut,
                                                                                        new Lz4Compressor(), 1024, 0);
                // close without write
                blockCompressorStream.Close();
                // check compressed output
                buf = bytesOut.ToByteArray();
                Assert.Equal("empty stream compressed output size != 4", 4, buf
                             .Length);
                // use compressed output as input for decompression
                bytesIn = new ByteArrayInputStream(buf);
                // create decompression stream
                blockDecompressorStream = new BlockDecompressorStream(bytesIn, new Lz4Decompressor
                                                                          (), 1024);
                // no byte is available because stream was closed
                Assert.Equal("return value is not -1", -1, blockDecompressorStream
                             .Read());
            }
            catch (Exception e)
            {
                NUnit.Framework.Assert.Fail("testCompressorDecompressorEmptyStreamLogic ex error !!!"
                                            + e.Message);
            }
            finally
            {
                if (blockDecompressorStream != null)
                {
                    try
                    {
                        bytesIn.Close();
                        bytesOut.Close();
                        blockDecompressorStream.Close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <exception cref="System.IO.IOException"/>
        private void TestRead(int bufLen)
        {
            // compress empty stream
            bytesOut = new ByteArrayOutputStream();
            if (bufLen > 0)
            {
                bytesOut.Write(((byte[])ByteBuffer.Allocate(bufLen).PutInt(1024).Array()), 0, bufLen
                               );
            }
            BlockCompressorStream blockCompressorStream = new BlockCompressorStream(bytesOut,
                                                                                    new FakeCompressor(), 1024, 0);

            // close without any write
            blockCompressorStream.Close();
            // check compressed output
            buf = bytesOut.ToByteArray();
            Assert.Equal("empty file compressed output size is not " + (bufLen
                                                                        + 4), bufLen + 4, buf.Length);
            // use compressed output as input for decompression
            bytesIn = new ByteArrayInputStream(buf);
            // get decompression stream
            BlockDecompressorStream blockDecompressorStream = new BlockDecompressorStream(bytesIn
                                                                                          , new FakeDecompressor(), 1024);

            try
            {
                Assert.Equal("return value is not -1", -1, blockDecompressorStream
                             .Read());
            }
            catch (IOException e)
            {
                NUnit.Framework.Assert.Fail("unexpected IOException : " + e);
            }
            finally
            {
                blockDecompressorStream.Close();
            }
        }