Prefuse 4未完

今天才发现,prefuse的官方用户手册没有写完,只能自己边研究边写了。

    之前用到一个GraphMLReader类的GraphReader函数,就先从他入手吧:

    1、GraphMlReader

    定义:

public class GraphMLReader extends AbstractGraphReader  implements GraphReader{
/***
.....
***/


   其中:GraphReader仅仅定义了四个不同参数reader函数,其内容为:

public interface GraphReader {
  public Graph readGraph(String location) throws DataIOException;
  public Graph readGraph(URL url) throws DataIOException;
  public Graph readGraph(File f) throws DataIOException;
  public Graph readGraph(InputStream is) throws DataIOException;
}

    AbstractGraphReader也是一个抽象类,对前三个Reader进行了实现,最后一个参数为InputStream is的仍然保留为抽象函数,但是,如果观察这些实现的函数会发现,所有的读入动作,最后都交给了public Graph readGraph(InputStream is) throws DataIOException; 函数来实现,这样具体怎么读入数据,就要看集成这个抽象类的类来决定了。

    而GraphMLReader直接对这个函数进行了实现:

public Graph readGraph(InputStream is) throws DataIOException {
        try {       
            SAXParserFactory factory   = SAXParserFactory.newInstance();
            SAXParser        saxParser = factory.newSAXParser();
            
            GraphMLHandler   handler   = new GraphMLHandler();
            System.out.println("here");
            saxParser.parse(is, handler);
            return handler.getGraph();
        } catch ( Exception e ) {
            if ( e instanceof DataIOException ) {
                throw (DataIOException)e;
            } else {
                throw new DataIOException(e);
            }
        }
    }

     其中SAXParserFactory,SAXParser是java提供的一个解析XML的库文件,输入的第一个参数为InputStream,第二个参数是DefaultHandler。这里的GraphMLHandler就是一个继承了DefaultHandler的静态类,见该文件中后边部分。

转载于:https://www.cnblogs.com/Joy06/p/3371794.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值