/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> private void TestPBDelimitedWriter(string db) { string Delimiter = "\t"; ByteArrayOutputStream output = new ByteArrayOutputStream(); using (TextWriter o = new TextWriter(output)) { PBImageDelimitedTextWriter v = new PBImageDelimitedTextWriter(o, Delimiter, db); v.Visit(new RandomAccessFile(originalFsimage, "r")); } ICollection <string> fileNames = new HashSet <string>(); using (ByteArrayInputStream input = new ByteArrayInputStream(output.ToByteArray() )) { using (BufferedReader reader = new BufferedReader(new InputStreamReader(input))) { string line; while ((line = reader.ReadLine()) != null) { System.Console.Out.WriteLine(line); string[] fields = line.Split(Delimiter); NUnit.Framework.Assert.AreEqual(12, fields.Length); fileNames.AddItem(fields[0]); } } } // writtenFiles does not contain root directory and "invalid XML char" dir. for (IEnumerator <string> it = fileNames.GetEnumerator(); it.HasNext();) { string filename = it.Next(); if (filename.StartsWith("/dirContainingInvalidXMLChar")) { it.Remove(); } else { if (filename.Equals("/")) { it.Remove(); } } } NUnit.Framework.Assert.AreEqual(writtenFiles.Keys, fileNames); }
/// <exception cref="System.Exception"/> public static int Run(string[] args) { Options options = BuildOptions(); if (args.Length == 0) { PrintUsage(); return(0); } CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.Parse(options, args); } catch (ParseException) { System.Console.Out.WriteLine("Error parsing command-line options: "); PrintUsage(); return(-1); } if (cmd.HasOption("h")) { // print help and exit PrintUsage(); return(0); } string inputFile = cmd.GetOptionValue("i"); string processor = cmd.GetOptionValue("p", "Web"); string outputFile = cmd.GetOptionValue("o", "-"); string delimiter = cmd.GetOptionValue("delimiter", PBImageDelimitedTextWriter.DefaultDelimiter ); string tempPath = cmd.GetOptionValue("t", string.Empty); Configuration conf = new Configuration(); try { using (TextWriter @out = outputFile.Equals("-") ? System.Console.Out : new TextWriter (outputFile, "UTF-8")) { switch (processor) { case "FileDistribution": { long maxSize = long.Parse(cmd.GetOptionValue("maxSize", "0")); int step = System.Convert.ToInt32(cmd.GetOptionValue("step", "0")); new FileDistributionCalculator(conf, maxSize, step, @out).Visit(new RandomAccessFile (inputFile, "r")); break; } case "XML": { new PBImageXmlWriter(conf, @out).Visit(new RandomAccessFile(inputFile, "r")); break; } case "Web": { string addr = cmd.GetOptionValue("addr", "localhost:5978"); using (WebImageViewer viewer = new WebImageViewer(NetUtils.CreateSocketAddr(addr) )) { viewer.Start(inputFile); } break; } case "Delimited": { using (PBImageDelimitedTextWriter writer = new PBImageDelimitedTextWriter(@out, delimiter , tempPath)) { writer.Visit(new RandomAccessFile(inputFile, "r")); } break; } } return(0); } } catch (EOFException) { System.Console.Error.WriteLine("Input file ended unexpectedly. Exiting"); } catch (IOException e) { System.Console.Error.WriteLine("Encountered exception. Exiting: " + e.Message); } return(-1); }