Exemple #1
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.TypeLoadException"/>
        /// <exception cref="InstantiationException"/>
        /// <exception cref="System.MemberAccessException"/>
        private static void SequenceFileCodecTest(Configuration conf, int lines, string codecClass
                                                  , int blockSize)
        {
            Path filePath = new Path("SequenceFileCodecTest." + codecClass);

            // Configuration
            conf.SetInt("io.seqfile.compress.blocksize", blockSize);
            // Create the SequenceFile
            FileSystem fs = FileSystem.Get(conf);

            Log.Info("Creating SequenceFile with codec \"" + codecClass + "\"");
            SequenceFile.Writer writer = SequenceFile.CreateWriter(fs, conf, filePath, typeof(
                                                                       Text), typeof(Text), SequenceFile.CompressionType.Block, (CompressionCodec)System.Activator.CreateInstance
                                                                       (Runtime.GetType(codecClass)));
            // Write some data
            Log.Info("Writing to SequenceFile...");
            for (int i = 0; i < lines; i++)
            {
                Text key   = new Text("key" + i);
                Text value = new Text("value" + i);
                writer.Append(key, value);
            }
            writer.Close();
            // Read the data back and check
            Log.Info("Reading from the SequenceFile...");
            SequenceFile.Reader reader  = new SequenceFile.Reader(fs, filePath, conf);
            Writable            key_1   = (Writable)System.Activator.CreateInstance(reader.GetKeyClass());
            Writable            value_1 = (Writable)System.Activator.CreateInstance(reader.GetValueClass
                                                                                        ());
            int lc = 0;

            try
            {
                while (reader.Next(key_1, value_1))
                {
                    Assert.Equal("key" + lc, key_1.ToString());
                    Assert.Equal("value" + lc, value_1.ToString());
                    lc++;
                }
            }
            finally
            {
                reader.Close();
            }
            Assert.Equal(lines, lc);
            // Delete temporary files
            fs.Delete(filePath, false);
            Log.Info("SUCCESS! Completed SequenceFileCodecTest with codec \"" + codecClass +
                     "\"");
        }
 /// <summary>Read key/value pair in a line.</summary>
 /// <exception cref="System.IO.IOException"/>
 public virtual bool Next(Text key, Text value)
 {
     lock (this)
     {
         Text tKey   = key;
         Text tValue = value;
         if (!sequenceFileRecordReader.Next(innerKey, innerValue))
         {
             return(false);
         }
         tKey.Set(innerKey.ToString());
         tValue.Set(innerValue.ToString());
         return(true);
     }
 }
Exemple #3
0
 /// <summary>
 /// Get number of raw data bytes of the
 /// <see cref="Org.Apache.Hadoop.IO.Writable"/>
 /// </summary>
 /// <param name="writable">
 ///
 /// <see cref="Org.Apache.Hadoop.IO.Writable"/>
 /// object from whom to get the raw data
 /// length
 /// </param>
 /// <returns>number of raw data bytes</returns>
 public virtual int GetRawBytesLength(Writable writable)
 {
     return(Sharpen.Runtime.GetBytesForString(writable.ToString()).Length);
 }
Exemple #4
0
 /// <summary>
 /// Get raw data bytes from a
 /// <see cref="Org.Apache.Hadoop.IO.Writable"/>
 /// </summary>
 /// <param name="writable">
 ///
 /// <see cref="Org.Apache.Hadoop.IO.Writable"/>
 /// object from whom to get the raw data
 /// </param>
 /// <returns>raw data of the writable</returns>
 public virtual byte[] GetRawBytes(Writable writable)
 {
     return(Sharpen.Runtime.GetBytesForString(writable.ToString()));
 }
Exemple #5
0
 protected void WriteValue(Writable value)
 {
     WriteLine(value.ToString());
 }