01: package prefuse.data.io;
02:
03: import java.io.File;
04: import java.io.FileInputStream;
05: import java.io.FileNotFoundException;
06: import java.io.IOException;
07: import java.io.InputStream;
08: import java.net.URL;
09:
10: import prefuse.data.Table;
11: import prefuse.util.io.IOLib;
12:
13: /**
14: * Abstract base class implementation of the TableReader interface. Provides
15: * implementations for all but the
16: * {@link prefuse.data.io.TableReader#readTable(InputStream)} method.
17: *
18: * @author <a href="http://jheer.org">jeffrey heer</a>
19: */
20: public abstract class AbstractTableReader implements TableReader {
21:
22: /**
23: * @see prefuse.data.io.TableReader#readTable(java.lang.String)
24: */
25: public Table readTable(String location) throws DataIOException {
26: try {
27: InputStream is = IOLib.streamFromString(location);
28: if (is == null)
29: throw new DataIOException(
30: "Couldn't find "
31: + location
32: + ". Not a valid file, URL, or resource locator.");
33: return readTable(is);
34: } catch (IOException e) {
35: throw new DataIOException(e);
36: }
37: }
38:
39: /**
40: * @see prefuse.data.io.TableReader#readTable(java.net.URL)
41: */
42: public Table readTable(URL url) throws DataIOException {
43: try {
44: return readTable(url.openStream());
45: } catch (IOException e) {
46: throw new DataIOException(e);
47: }
48: }
49:
50: /**
51: * @see prefuse.data.io.TableReader#readTable(java.io.File)
52: */
53: public Table readTable(File f) throws DataIOException {
54: try {
55: return readTable(new FileInputStream(f));
56: } catch (FileNotFoundException e) {
57: throw new DataIOException(e);
58: }
59: }
60:
61: } // end of abstract class AbstractTableReader
|