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"); } } }
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); } } }
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); }
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; } } }
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; } } }