Changeset 3218


Ignore:
Timestamp:
10/02/07 10:29:03 (12 years ago)
Author:
curtis
Message:

Allow processing from stdin.

Location:
trunk/loci/formats/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/tools/XMLIndent.java

    r3145 r3218  
    2525package loci.formats.tools; 
    2626 
    27 import java.io.BufferedReader; 
    28 import java.io.FileReader; 
     27import java.io.*; 
    2928import loci.formats.XMLTools; 
    3029 
     
    3837public class XMLIndent { 
    3938 
     39  public static void process(BufferedReader in) throws IOException { 
     40    StringBuffer sb = new StringBuffer(); 
     41    while (true) { 
     42      String line = in.readLine(); 
     43      if (line == null) break; 
     44      sb.append(line); 
     45    } 
     46    in.close(); 
     47    System.out.println(XMLTools.indentXML(sb.toString())); 
     48  } 
     49 
    4050  public static void main(String[] args) throws Exception { 
    41     for (int i=0; i<args.length; i++) { 
    42       String f = args[i]; 
    43       BufferedReader in = new BufferedReader(new FileReader(f)); 
    44       StringBuffer sb = new StringBuffer(); 
    45       while (true) { 
    46         String line = in.readLine(); 
    47         if (line == null) break; 
    48         sb.append(line); 
     51    if (args.length == 0) { 
     52      // read from stdin 
     53      process(new BufferedReader(new InputStreamReader(System.in))); 
     54    } 
     55    else { 
     56      // read from file(s) 
     57      for (int i=0; i<args.length; i++) { 
     58        process(new BufferedReader(new FileReader(args[i]))); 
    4959      } 
    50       in.close(); 
    51       System.out.println(XMLTools.indentXML(sb.toString())); 
    5260    } 
    5361  } 
  • trunk/loci/formats/tools/XMLValidate.java

    r3145 r3218  
    2525package loci.formats.tools; 
    2626 
    27 import java.io.BufferedReader; 
    28 import java.io.FileReader; 
     27import java.io.*; 
    2928import loci.formats.XMLTools; 
    3029 
     
    3837public class XMLValidate { 
    3938 
     39  public static void process(String label, BufferedReader in) 
     40    throws IOException 
     41  { 
     42    StringBuffer sb = new StringBuffer(); 
     43    while (true) { 
     44      String line = in.readLine(); 
     45      if (line == null) break; 
     46      sb.append(line); 
     47    } 
     48    in.close(); 
     49    XMLTools.validateXML(sb.toString(), label); 
     50  } 
     51 
    4052  public static void main(String[] args) throws Exception { 
    41     for (int i=0; i<args.length; i++) { 
    42       String f = args[i]; 
    43       BufferedReader in = new BufferedReader(new FileReader(f)); 
    44       StringBuffer sb = new StringBuffer(); 
    45       while (true) { 
    46         String line = in.readLine(); 
    47         if (line == null) break; 
    48         sb.append(line); 
     53    if (args.length == 0) { 
     54      // read from stdin 
     55      process("<stdin>", new BufferedReader(new InputStreamReader(System.in))); 
     56    } 
     57    else { 
     58      // read from file(s) 
     59      for (int i=0; i<args.length; i++) { 
     60        process(args[i], new BufferedReader(new FileReader(args[i]))); 
    4961      } 
    50       in.close(); 
    51       XMLTools.validateXML(sb.toString(), args[i]); 
    5262    } 
    5363  } 
Note: See TracChangeset for help on using the changeset viewer.