KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > data > io > AbstractGraphReader


1 package prefuse.data.io;
2
3 import java.io.File JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5 import java.io.FileNotFoundException JavaDoc;
6 import java.io.IOException JavaDoc;
7 import java.io.InputStream JavaDoc;
8 import java.net.URL JavaDoc;
9
10 import prefuse.data.Graph;
11 import prefuse.util.io.IOLib;
12
13
14 /**
15  * Abstract base class implementation of the GraphReader interface. Provides
16  * implementations for all but the
17  * {@link prefuse.data.io.GraphReader#readGraph(InputStream)} method.
18  *
19  * @author <a HREF="http://jheer.org">jeffrey heer</a>
20  */

21 public abstract class AbstractGraphReader implements GraphReader {
22
23     /**
24      * @see prefuse.data.io.GraphReader#readGraph(java.lang.String)
25      */

26     public Graph readGraph(String JavaDoc location) throws DataIOException
27     {
28         try {
29             InputStream JavaDoc is = IOLib.streamFromString(location);
30             if ( is == null )
31                 throw new DataIOException("Couldn't find " + location
32                     + ". Not a valid file, URL, or resource locator.");
33             return readGraph(is);
34         } catch ( IOException JavaDoc e ) {
35             throw new DataIOException(e);
36         }
37     }
38
39     /**
40      * @see prefuse.data.io.GraphReader#readGraph(java.net.URL)
41      */

42     public Graph readGraph(URL JavaDoc url) throws DataIOException {
43         try {
44             return readGraph(url.openStream());
45         } catch ( IOException JavaDoc e ) {
46             throw new DataIOException(e);
47         }
48     }
49
50     /**
51      * @see prefuse.data.io.GraphReader#readGraph(java.io.File)
52      */

53     public Graph readGraph(File JavaDoc f) throws DataIOException {
54         try {
55             return readGraph(new FileInputStream JavaDoc(f));
56         } catch ( FileNotFoundException JavaDoc e ) {
57             throw new DataIOException(e);
58         }
59     }
60     
61     /**
62      * @see prefuse.data.io.GraphReader#readGraph(java.io.InputStream)
63      */

64     public abstract Graph readGraph(InputStream JavaDoc is) throws DataIOException;
65
66 } // end of class AbstractGraphReader
67
Popular Tags