예제 #1
0
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual void ReadObject(Writable obj, DataInputStream inStream
                                                   )
        {
            int numBytes = WritableUtils.ReadVInt(inStream);

            byte[] buffer;
            // For BytesWritable and Text, use the specified length to set the length
            // this causes the "obvious" translations to work. So that if you emit
            // a string "abc" from C++, it shows up as "abc".
            if (obj is BytesWritable)
            {
                buffer = new byte[numBytes];
                inStream.ReadFully(buffer);
                ((BytesWritable)obj).Set(buffer, 0, numBytes);
            }
            else
            {
                if (obj is Text)
                {
                    buffer = new byte[numBytes];
                    inStream.ReadFully(buffer);
                    ((Text)obj).Set(buffer);
                }
                else
                {
                    obj.ReadFields(inStream);
                }
            }
        }
예제 #2
0
        /// <summary>Utility method for testing writables.</summary>
        /// <exception cref="System.Exception"/>
        public static Writable TestWritable(Writable before, Configuration conf)
        {
            DataOutputBuffer dob = new DataOutputBuffer();

            before.Write(dob);
            DataInputBuffer dib = new DataInputBuffer();

            dib.Reset(dob.GetData(), dob.GetLength());
            Writable after = (Writable)ReflectionUtils.NewInstance(before.GetType(), conf);

            after.ReadFields(dib);
            Assert.Equal(before, after);
            return(after);
        }
예제 #3
0
        /// <summary>Utility method for testing VersionedWritables.</summary>
        /// <exception cref="System.Exception"/>
        public static void TestVersionedWritable(Writable before, Writable after)
        {
            DataOutputBuffer dob = new DataOutputBuffer();

            before.Write(dob);
            DataInputBuffer dib = new DataInputBuffer();

            dib.Reset(dob.GetData(), dob.GetLength());
            try
            {
                after.ReadFields(dib);
            }
            catch (VersionMismatchException vmme)
            {
                System.Console.Out.WriteLine("Good, we expected this:" + vmme);
                return;
            }
            throw new Exception("A Version Mismatch Didn't Happen!");
        }