001: // Resolve.java
002: // $Id: Resolve.java,v 1.3 2000/08/16 21:37:50 ylafon Exp $
003: // (c) COPYRIGHT MIT, INRIA and Keio, 1996-1999.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: // a small log resolver that can add timestamps for sorting.
007: // @author Yves Lafon <ylafon@w3.org>
008:
009: package org.w3c.tools.log;
010:
011: import java.io.BufferedReader;
012: import java.io.File;
013: import java.io.FileNotFoundException;
014: import java.io.FileReader;
015: import java.io.InputStreamReader;
016: import java.io.PrintStream;
017:
018: /**
019: * A simple and a little specific resolver
020: * It can add numeric timestamps to ease the sort of the logfile
021: * It can do DNS resolution (of course) using multiple threads
022: * a -help explains all ;)
023: */
024:
025: public class Resolve {
026:
027: public static void main(String args[]) {
028:
029: BufferedReader bf = null;
030: int maxThread = 0;
031: boolean usage = false;
032: int offset = 0;
033: boolean timestamp = true;
034: boolean resolve = true;
035: DNSResolver resolver;
036:
037: if (args.length > 0) {
038: while (args.length - offset > 0
039: && args[offset].charAt(0) == '-') {
040: if (args[offset].equals("-thmax")) {
041: offset++;
042: if (resolve) {
043: try {
044: maxThread = Integer.parseInt(args[offset]);
045: } catch (NumberFormatException nfe) {
046: usage = true;
047: }
048: }
049: } else if (args[0].equals("-notime")) {
050: timestamp = false;
051: } else if (args[0].equals("-nores")) {
052: timestamp = true;
053: resolve = false;
054: } else if (args[0].equals("-help")) {
055: usage = true;
056: } else {
057: usage = true;
058: }
059: offset++;
060: }
061: }
062: if (usage) {
063: System.out.println("Usage: java org.w3c.tools.log.Resolve "
064: + " [-notime] [-nores] [-thmax #] [logfile]*");
065: System.out.println(" it can also read from stdin.");
066: System.out.println(" java -help");
067: System.exit(0);
068: }
069: if (args.length - offset > 0) {
070: while (offset < args.length) {
071: File logfile = new File(args[offset]);
072: FileReader fr;
073:
074: if (!logfile.exists()) {
075: System.err.println("No logfile of this name :"
076: + args[offset]);
077: System.exit(1);
078: }
079: try {
080: fr = new FileReader(logfile);
081: } catch (FileNotFoundException ex) {
082: System.err.println("log file " + args[offset]
083: + "not found!");
084: return;
085: }
086: bf = new BufferedReader(fr);
087: if (maxThread != 0)
088: resolver = new DNSResolver(bf, maxThread,
089: timestamp, resolve);
090: else
091: resolver = new DNSResolver(bf, timestamp, resolve);
092: resolver.readLog();
093: offset++;
094: }
095: } else {
096: bf = new BufferedReader(new InputStreamReader(System.in));
097: if (maxThread != 0)
098: resolver = new DNSResolver(bf, maxThread, timestamp,
099: resolve);
100: else
101: resolver = new DNSResolver(bf, timestamp, resolve);
102: resolver.readLog();
103: }
104: }
105: }
|