File: Time.java

package info (click to toggle)
lib-xp-java 0.5-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,652 kB
  • ctags: 2,424
  • sloc: java: 8,085; makefile: 53; sh: 17; xml: 7
file content (50 lines) | stat: -rw-r--r-- 1,562 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.jclark.xml.apps;

import java.io.IOException;

import com.jclark.xml.parse.io.Parser;
import com.jclark.xml.parse.io.ParserImpl;
import com.jclark.xml.parse.EntityManagerImpl;
import com.jclark.xml.parse.OpenEntity;
import com.jclark.xml.parse.NotWellFormedException;

/**
 * @version $Revision: 1.6 $ $Date: 1998/05/08 06:42:22 $
 */
public class Time {

  /**
   * Each of the specified argument is treated as the name
   * of a file containing an XML document to be parsed.
   * If no arguments are specified, the standard input is read.
   * The total time in seconds for the parse is reported
   * on the standard output.
   * For each document that is not well-formed, a message
   * is written in the standard error.
   */
  public static void main(String args[]) throws IOException {
    long startTime = System.currentTimeMillis();
    boolean hadErr = false;
    if (args.length == 0)
      hadErr = !parseEntity(EntityManagerImpl.openStandardInput());
    else {
      for (int i = 0; i < args.length; i++)
	if (!parseEntity(EntityManagerImpl.openFile(args[i])))
	  hadErr = true;
    }
    System.out.println((System.currentTimeMillis() - startTime)/1000.0);
    System.exit(hadErr ? 1 : 0);
  }

  static boolean parseEntity(OpenEntity entity) throws IOException {
    Parser parser = new ParserImpl();
    try {
      parser.parseDocument(entity);
      return true;
    }
    catch (NotWellFormedException e) {
      System.err.println(e.getMessage());
      return false;
    }
  }
}