Esempio n. 1
0
        /// <exception cref="System.IO.IOException"/>
        public static void TestReadInRange(long val, int lower, int upper, bool expectSuccess
                                           )
        {
            DataOutputBuffer buf   = new DataOutputBuffer();
            DataInputBuffer  inbuf = new DataInputBuffer();

            WritableUtils.WriteVLong(buf, val);
            try
            {
                inbuf.Reset(buf.GetData(), 0, buf.GetLength());
                long val2 = WritableUtils.ReadVIntInRange(inbuf, lower, upper);
                if (!expectSuccess)
                {
                    Fail("expected readVIntInRange to throw an exception");
                }
                Assert.Equal(val, val2);
            }
            catch (IOException e)
            {
                if (expectSuccess)
                {
                    Log.Error("unexpected exception:", e);
                    Fail("readVIntInRange threw an unexpected exception");
                }
            }
        }
Esempio n. 2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestIO()
        {
            DataOutputBuffer @out = new DataOutputBuffer();
            DataInputBuffer  @in  = new DataInputBuffer();

            for (int i = 0; i < NumIterations; i++)
            {
                // generate a random string
                string before;
                if (i == 0)
                {
                    before = GetLongString();
                }
                else
                {
                    before = GetTestString();
                }
                // write it
                @out.Reset();
                Org.Apache.Hadoop.IO.Text.WriteString(@out, before);
                // test that it reads correctly
                @in.Reset(@out.GetData(), @out.GetLength());
                string after = Org.Apache.Hadoop.IO.Text.ReadString(@in);
                Assert.True(before.Equals(after));
                // Test compatibility with Java's other decoder
                int strLenSize = WritableUtils.GetVIntSize(Org.Apache.Hadoop.IO.Text.Utf8Length(before
                                                                                                ));
                string after2 = Runtime.GetStringForBytes(@out.GetData(), strLenSize, @out
                                                          .GetLength() - strLenSize, "UTF-8");
                Assert.True(before.Equals(after2));
            }
        }
Esempio n. 3
0
 /// <exception cref="System.IO.IOException"/>
 public override void ReadFields(BinaryReader reader)
 {
     base.ReadFields(@in);
     shortTestString        = @in.ReadUTF();
     longTestString         = WritableUtils.ReadString(@in);
     compressableTestString = WritableUtils.ReadCompressedString(@in);
     containedObject.ReadFields(@in);
     // Warning if this is a recursive call, you need a null value.
     testStringArray = WritableUtils.ReadStringArray(@in);
 }
Esempio n. 4
0
            /// <exception cref="System.IO.IOException"/>
            public override void Write(BinaryWriter writer)
            {
                base.Write(@out);
                @out.WriteUTF(shortTestString);
                WritableUtils.WriteString(@out, longTestString);
                int comp = WritableUtils.WriteCompressedString(@out, compressableTestString);

                System.Console.Out.WriteLine("Compression is " + comp + "%");
                containedObject.Write(@out);
                // Warning if this is a recursive call, you need a null value.
                WritableUtils.WriteStringArray(@out, testStringArray);
            }
Esempio n. 5
0
        /// <exception cref="System.IO.IOException"/>
        public static void TestValue(int val, int vintlen)
        {
            DataOutputBuffer buf   = new DataOutputBuffer();
            DataInputBuffer  inbuf = new DataInputBuffer();

            WritableUtils.WriteVInt(buf, val);
            if (Log.IsDebugEnabled())
            {
                Log.Debug("Value = " + val);
                BytesWritable printer = new BytesWritable();
                printer.Set(buf.GetData(), 0, buf.GetLength());
                Log.Debug("Buffer = " + printer);
            }
            inbuf.Reset(buf.GetData(), 0, buf.GetLength());
            Assert.Equal(val, WritableUtils.ReadVInt(inbuf));
            Assert.Equal(vintlen, buf.GetLength());
            Assert.Equal(vintlen, WritableUtils.GetVIntSize(val));
            Assert.Equal(vintlen, WritableUtils.DecodeVIntSize(buf.GetData
                                                                   ()[0]));
        }
Esempio n. 6
0
            public override void Run()
            {
                string           name = this.GetName();
                DataOutputBuffer @out = new DataOutputBuffer();
                DataInputBuffer  @in  = new DataInputBuffer();

                for (int i = 0; i < 1000; ++i)
                {
                    try
                    {
                        @out.Reset();
                        WritableUtils.WriteString(@out, name);
                        @in.Reset(@out.GetData(), @out.GetLength());
                        string s = WritableUtils.ReadString(@in);
                        Assert.Equal("input buffer reset contents = " + name, name, s);
                    }
                    catch (Exception ioe)
                    {
                        throw new RuntimeException(ioe);
                    }
                }
            }
Esempio n. 7
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void Write(BinaryWriter writer)
 {
     WritableUtils.WriteVInt(@out, value);
 }
Esempio n. 8
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void ReadFields(BinaryReader reader)
 {
     value = WritableUtils.ReadVInt(@in);
 }