import java.io.*;
import java.net.*;
import java.util.*;
public class tsvContentTester implements ContentHandlerFactory {
String theURL;
public static void main (String[] args) {
if (args.length == 1) {
tsvContentTester ct = new tsvContentTester(args[0]);
URLConnection.setContentHandlerFactory(ct);
ct.test();
}
else {
System.err.println("Usage: java tsvContentTester url");
}
}
public tsvContentTester(String s) {
theURL = s;
}
public void test() {
String theLine;
try {
URL u = new URL(theURL);
Vector v = (Vector) u.getContent();
for (Enumeration e = v.elements() ; e.hasMoreElements() ;) {
String[] sa = (String[]) e.nextElement();
for (int i = 0; i < sa.length; i++) {
System.out.print(sa[i] + "\t");
}
System.out.println();
}
}
catch (IOException e) {
System.err.println(e);
}
}
public ContentHandler createContentHandler(String type) {
if (type.equalsIgnoreCase("text/tab-separated-values")) {
return new tabSeparatedValueHandler();
}
else {
return null;
}
}
}
|