Exemple #1
0
 private static void Decode(string inputPath, string outputPath)
 {
     using (var reader = new RecordReader(inputPath))
         using (var writer = new StreamWriter(outputPath))
         {
             while (reader.HasNext())
             {
                 writer.Write(reader.Next().Info + "\n");
             }
         }
 }
Exemple #2
0
 private static void PrintFile(string path)
 {
     Console.WriteLine("  Print file: " + path);
     using (var rr = new RecordReader(path))
     {
         while (rr.HasNext())
         {
             Console.WriteLine("  " + rr.Next().Info);
         }
     }
 }
Exemple #3
0
        public static List <Record> ReadAll(string path)
        {
            var list = new List <Record>();

            using (var rr = new RecordReader(path))
            {
                while (rr.HasNext())
                {
                    list.Add(rr.Next());
                }
            }

            return(list);
        }
Exemple #4
0
        private static void Dedup(string inputFile, out string outputFile)
        {
            outputFile = GetTempFileName();

            using (var reader = new RecordReader(inputFile))
                using (var writer = new RecordWriter(outputFile))
                {
                    Record prev = null;
                    while (reader.HasNext())
                    {
                        var curr = reader.Next();
                        if (prev == null || !curr.Info.Equals(prev.Info))
                        {
                            writer.Write(curr);
                        }

                        prev = curr;
                    }
                }
        }
Exemple #5
0
        private static void Merge(string inputFile1, string inputFile2, out string outputFile, IComparer <Record> comparer)
        {
            outputFile = GetTempFileName();

            using (var reader1 = new RecordReader(inputFile1))
                using (var reader2 = new RecordReader(inputFile2))
                    using (var writer = new RecordWriter(outputFile))
                    {
                        var record1 = reader1.Next();
                        var record2 = reader2.Next();

                        while (record1 != null && record2 != null)
                        {
                            if (comparer.Compare(record1, record2) <= 0)
                            {
                                writer.Write(record1);
                                record1 = reader1.HasNext() ? reader1.Next() : null;
                            }
                            else
                            {
                                writer.Write(record2);
                                record2 = reader2.HasNext() ? reader2.Next() : null;
                            }
                        }

                        while (record1 != null)
                        {
                            writer.Write(record1);
                            record1 = reader1.HasNext() ? reader1.Next() : null;
                        }

                        while (record2 != null)
                        {
                            writer.Write(record2);
                            record2 = reader2.HasNext() ? reader2.Next() : null;
                        }
                    }
        }