View Javadoc

1   package org.astrogrid.mySpace.mySpaceUtil;
2   
3   import java.io.BufferedReader;
4   import java.util.StringTokenizer;
5   import java.util.Vector;
6   
7   class FileTransferTestCase {
8   
9     private String[] urls;
10    private int      urlIndex  = 0;
11    private boolean  endOfFile = false;
12    private boolean  hasTests  = false;
13  
14  
15    /***
16     * Constructs a FileTransferTestCase by parsing the next line from
17     * a given BufferedReader.
18     */
19    public FileTransferTestCase (BufferedReader b) throws Exception {
20      String l = b.readLine();
21      if (l == null) {
22  	  this.endOfFile = true;
23      }
24      else {
25        System.out.println();
26        System.out.println("Test sources: " + l);
27        Vector v = new Vector();
28        StringTokenizer t = new StringTokenizer(l, " ");
29  
30        // The first token can be null (blank line), hash
31        // (comment line) or an integer (indicates the index
32        // counted from zero of the URL in the following list that is
33        // expected to perform the transfer successfully.
34        String q;
35        try {
36          q = t.nextToken();
37        }
38        catch (Exception e) {
39  		q = null;
40        }
41        if (q != null && !"#".equals(q)) {
42          this.urlIndex = Integer.parseInt(q);
43  
44          // The subsequent tokens are all URLS to be tried in the transfer.
45          while (t.hasMoreTokens()) {
46            String u = t.nextToken();
47            v.addElement(u);
48          }
49          urls = new String[v.size()];
50          for (int i = 0; i < urls.length; i++) {
51            urls[i] = (String)v.elementAt(i);
52          }
53          this.hasTests = true;
54  	  }
55      }
56    }
57  
58  
59    /***
60     * Returns the set of source URLs obtained during construction.
61     * This array may be null if the constructor found no more data
62     * to parse.
63     */
64    public String[] getSourceUrls () {
65  	return this.urls;
66    }
67  
68  
69    /***
70     * Returns the index of the URL expected to complete
71     * the transfer.  The index appies to the String array
72     * returned by {@link getSourceUrls} and is thus counted
73     * from zero.
74     */
75    public int getUrlIndex () {
76  	return this.urlIndex;
77    }
78  
79  
80    /***
81     * Indicates if the end of the file of test cases has been reached.
82     *
83     * @return true if the end of the file has been reached, false otherwise.
84     */
85    public boolean isEndOfFile () {
86  	return this.endOfFile;
87    }
88  
89  
90    /***
91     * Indicates whether this object has data for a test case.
92     * Normally, constructing the object reads in data for one test
93     * case from the next line of the file.  If the next line is
94     * blank or a comment, or if there is no next line, then the
95     * object has no useful test data and must be discarded.
96     */
97    public boolean isUsefulTestCase () {
98  	return this.hasTests;
99    }
100 
101 }