Process a script against a single input file. @param s script to execute. @param reader input file. @param pw output sink.
(Script s, BufferedReader reader, PrintWriter pw)
| 662 | * @param pw output sink. |
| 663 | */ |
| 664 | private void processReader(Script s, BufferedReader reader, PrintWriter pw) throws IOException { |
| 665 | String line; |
| 666 | String lineCountName = "count"; |
| 667 | s.setProperty(lineCountName, BigInteger.ZERO); |
| 668 | String autoSplitName = "split"; |
| 669 | s.setProperty("out", pw); |
| 670 | |
| 671 | try { |
| 672 | InvokerHelper.invokeMethod(s, "begin", null); |
| 673 | } catch (MissingMethodException mme) { |
| 674 | // ignore the missing method exception |
| 675 | // as it means no begin() method is present |
| 676 | } |
| 677 | |
| 678 | while ((line = reader.readLine()) != null) { |
| 679 | s.setProperty("line", line); |
| 680 | s.setProperty(lineCountName, ((BigInteger)s.getProperty(lineCountName)).add(BigInteger.ONE)); |
| 681 | |
| 682 | if(autoSplit) { |
| 683 | s.setProperty(autoSplitName, line.split(splitPattern)); |
| 684 | } |
| 685 | |
| 686 | Object o = s.run(); |
| 687 | |
| 688 | if (autoOutput && o != null) { |
| 689 | pw.println(o); |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | try { |
| 694 | InvokerHelper.invokeMethod(s, "end", null); |
| 695 | } catch (MissingMethodException mme) { |
| 696 | // ignore the missing method exception |
| 697 | // as it means no end() method is present |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * Process the standard, single script with args. |
no test coverage detected