// pnyx -e=documentation pncs.cmd.examples.documentation.library.ExampleProcessorChain processorChain public static void processorChain() { StreamInformation streamInformation = new StreamInformation(new Settings()); // Writes to STDOUT ILineProcessor dest = new LineProcessorToStream(streamInformation, Console.OpenStandardOutput()); // Grep filter / processor pair ILineFilter grepFilter = new Grep { textToFind = "world", caseSensitive = false }; ILineProcessor grepProcessor = new LineFilterProcessor { filter = grepFilter, processor = dest }; // Sed transformer / processor pair ILineTransformer sedTransformer = new SedReplace("World", "World, with love from Pnyx..", null); ILineProcessor sedProcessor = new LineTransformerProcessor { transform = sedTransformer, processor = grepProcessor }; // Reads from source using (StringStreamFactory streamFactory = new StringStreamFactory("Hello World.")) { using (StreamToLineProcessor source = new StreamToLineProcessor(streamInformation, streamFactory)) { source.setNextLineProcessor(sedProcessor); // Runs source.process(); // All I/O occurs on this step } } // outputs: Hello World, with love from Pnyx... }
private List <List <String> > parseRows(String source, Action <CsvStreamToRowProcessor> callback = null) { StreamInformation si = new StreamInformation(new Settings()); CsvStreamToRowProcessor csvProcess = new CsvStreamToRowProcessor(); StringStreamFactory wrapper = new StringStreamFactory(source); csvProcess.setSource(si, wrapper); CaptureRowProcessor capture = new CaptureRowProcessor(); csvProcess.setNextRowProcessor(capture); if (callback != null) { callback(csvProcess); } try { csvProcess.process(); return(capture.rows); } finally { try { wrapper.Dispose(); } catch (Exception) { } try { csvProcess.Dispose(); } catch (Exception) { } } }