View Javadoc

1   package net.sf.tourviewer;
2   
3   import java.io.BufferedInputStream;
4   import java.io.FileInputStream;
5   import java.io.IOException;
6   import java.io.InputStream;
7   import java.util.Arrays;
8   import net.sf.tourviewer.lib.Tour;
9   import net.sf.tourviewer.lib.TourRecord;
10  import net.sf.tourviewer.lib.TourSet;
11  import net.sf.tourviewer.lib.ciclo.CicloRawReader;
12  
13  public class JTourViewer 
14  {
15  
16  	private static final int HAC4_SIGNATURE = 0xB735;
17  	private static final int CM414M_SIGNATURE = 0xB723;
18  
19  	public TourSet read(String filename) throws IOException {
20      	InputStream in = new BufferedInputStream(new FileInputStream(filename));
21      	try {
22      		CicloRawReader reader = new CicloRawReader();
23      		if (reader.accept(in)) {
24      			TourSet tourSet = reader.read(in);
25      			//reader.print(System.out);
26      			print(tourSet);
27          		return tourSet;
28      		}
29      		else {
30      			throw new IOException("No handler for input file");
31      		}
32      	}
33      	finally { 
34      		try { 
35      			in.close(); 
36      		} catch (Exception e) {} 
37      	}
38  	}
39  	
40  	private void print(TourSet tourSet)
41  	{
42  		System.out.println(tourSet);
43  		Tour[] tours = tourSet.getTours();
44  		Arrays.sort(tours);
45  		for (Tour tour : tours) {
46  			System.out.println(tour);
47  		}
48  		System.out.println();
49  		
50  		for (Tour tour : tours) {
51  			System.out.println(tour);
52  			for (TourRecord record : tour.getRecords()) {
53  				System.out.println(record);
54  			}
55  			System.out.println();
56  		}
57  
58  	}
59  
60  	public static void main( String[] args )
61      {
62      	if (args.length != 1) {
63      		System.err.println("usage: java JTourViewer [filename]");
64      		System.exit(1);
65      	}
66      	
67      	JTourViewer app = new JTourViewer();
68      	try {
69  	    	app.read(args[0]);
70  		}
71  		catch (Exception e) {
72  			e.printStackTrace();
73  		}
74      }
75  
76  }