001: /**
002: *
003: * Copyright (C) 2004 Enterprise Distributed Technologies Ltd
004: *
005: * www.enterprisedt.com
006: *
007: * Change Log:
008: *
009: * $Log: FileParserTest.java,v $
010: * Revision 1.5 2007-10-12 05:21:54 bruceb
011: * test locales
012: *
013: * Revision 1.4 2007/03/28 06:04:57 bruceb
014: * add locale arg
015: *
016: * Revision 1.3 2005/06/03 11:27:05 bruceb
017: * comment update
018: *
019: * Revision 1.2 2004/10/19 16:16:08 bruceb
020: * made test more realistic
021: *
022: * Revision 1.1 2004/09/17 14:23:03 bruceb
023: * test harness
024: *
025: *
026: */package com.enterprisedt.net.ftp.test;
027:
028: import java.io.BufferedReader;
029: import java.io.FileReader;
030: import java.io.IOException;
031: import java.text.ParseException;
032: import java.util.Locale;
033: import java.util.Vector;
034:
035: import com.enterprisedt.net.ftp.FTPException;
036: import com.enterprisedt.net.ftp.FTPFile;
037: import com.enterprisedt.net.ftp.FTPFileFactory;
038: import com.enterprisedt.util.debug.Level;
039: import com.enterprisedt.util.debug.Logger;
040:
041: /**
042: * Test harness for testing out listings. Simply copy and
043: * paste a listing into a file and use this test harness to
044: * pinpoint the error
045: *
046: * @author Bruce Blackshaw
047: * @version $Revision: 1.5 $
048: */
049: public class FileParserTest {
050:
051: /**
052: * Standard main()
053: *
054: * @param args standard args - supply filename
055: */
056: public static void main(String[] args) {
057: if (args.length < 2) {
058: usage();
059: }
060:
061: Logger log = Logger.getLogger(FileParserTest.class);
062: Logger.setLevel(Level.ALL);
063:
064: String type = args[0];
065: String filename = args[1];
066: String locale = null;
067: if (args.length == 3)
068: locale = args[2];
069: if (!type.equalsIgnoreCase("UNIX")
070: && !type.equalsIgnoreCase("WINDOWS")
071: && !type.equalsIgnoreCase("VMS")) {
072: usage();
073: }
074: log.debug("Type=" + type);
075:
076: Vector lines = new Vector();
077: BufferedReader reader = null;
078: String line = null;
079: try {
080: FTPFileFactory ff = new FTPFileFactory(type);
081: if (locale != null) {
082: System.out.println("Setting locale to " + locale);
083: Locale l = new Locale(locale.toLowerCase(), locale
084: .toUpperCase());
085: Locale[] locales = new Locale[2];
086: locales[0] = Locale.ENGLISH;
087: locales[1] = l;
088: ff.setLocales(locales);
089: } else {
090: Locale[] locales = new Locale[1];
091: locales[0] = Locale.ENGLISH;
092: ff.setLocales(locales);
093: }
094: reader = new BufferedReader(new FileReader(filename));
095: while ((line = reader.readLine()) != null) {
096: lines.addElement(line);
097: System.out.println(line);
098: }
099: String[] listings = new String[lines.size()];
100: lines.copyInto(listings);
101: FTPFile[] files = ff.parse(listings);
102: for (int i = 0; i < files.length; i++)
103: System.out.println(files[i].toString());
104: } catch (IOException ex) {
105: System.out.println("Failed to read file: " + filename);
106: ex.printStackTrace();
107: } catch (ParseException ex) {
108: System.out.println("Failed to parse line '" + line + "'");
109: ex.printStackTrace();
110: } catch (FTPException ex) {
111: System.out.println("Failed to parse line '" + line + "'");
112: ex.printStackTrace();
113: }
114: }
115:
116: /**
117: * Usage statement
118: *
119: */
120: private static void usage() {
121: System.out
122: .println("Usage: FileParserTest UNIX|WINDOWS|VMS filename");
123: System.exit(-1);
124: }
125:
126: }
|