public void testCompressedSeek()
        {
            CompressionCodec codec = new SnappyCodec();

            TestInStream.OutputCollector collect = new TestInStream.OutputCollector();
            RunLengthByteWriter          @out    = new RunLengthByteWriter(new OutStream("test", 500,
                                                                                         codec, collect));

            TestInStream.PositionCollector[] positions =
                new TestInStream.PositionCollector[2048];
            for (int i = 0; i < 2048; ++i)
            {
                positions[i] = new TestInStream.PositionCollector();
                @out.getPosition(positions[i]);
                if (i < 1024)
                {
                    @out.write((byte)(i / 4));
                }
                else
                {
                    @out.write((byte)i);
                }
            }
            @out.flush();
            ByteBuffer inBuf = ByteBuffer.allocate(collect.buffer.size());

            collect.buffer.setByteBuffer(inBuf, 0, collect.buffer.size());
            inBuf.flip();
            RunLengthByteReader @in = new RunLengthByteReader(InStream.create(null, "test",
                                                                              new ByteBuffer[] { inBuf }, new long[] { 0 }, inBuf.remaining(), codec, 500));

            for (int i = 0; i < 2048; ++i)
            {
                int x = @in.next() & 0xff;
                if (i < 1024)
                {
                    Assert.Equal((i / 4) & 0xff, x);
                }
                else
                {
                    Assert.Equal(i & 0xff, x);
                }
            }
            for (int i = 2047; i >= 0; --i)
            {
                @in.seek(positions[i]);
                int x = @in.next() & 0xff;
                if (i < 1024)
                {
                    Assert.Equal((i / 4) & 0xff, x);
                }
                else
                {
                    Assert.Equal(i & 0xff, x);
                }
            }
        }
        public void testSkips()
        {
            TestInStream.OutputCollector collect = new TestInStream.OutputCollector();
            RunLengthByteWriter          @out    = new RunLengthByteWriter(new OutStream("test", 100,
                                                                                         null, collect));

            for (int i = 0; i < 2048; ++i)
            {
                if (i < 1024)
                {
                    @out.write((byte)(i / 16));
                }
                else
                {
                    @out.write((byte)i);
                }
            }
            @out.flush();
            ByteBuffer inBuf = ByteBuffer.allocate(collect.buffer.size());

            collect.buffer.setByteBuffer(inBuf, 0, collect.buffer.size());
            inBuf.flip();
#pragma warning disable 612
            RunLengthByteReader @in = new RunLengthByteReader(InStream.create(null, "test",
                                                                              new ByteBuffer[] { inBuf }, new long[] { 0 }, inBuf.remaining(), null, 100));
#pragma warning restore 612
            for (int i = 0; i < 2048; i += 10)
            {
                int x = @in.next() & 0xff;
                if (i < 1024)
                {
                    Assert.Equal((i / 16) & 0xff, x);
                }
                else
                {
                    Assert.Equal(i & 0xff, x);
                }
                if (i < 2038)
                {
                    @in.skip(9);
                }
                @in.skip(0);
            }
        }
Exemplo n.º 3
0
 public BitFieldWriter(PositionedOutputStream output, int bitSize)
 {
     this.output  = new RunLengthByteWriter(output);
     this.bitSize = bitSize;
 }