需要解决此问题:java.io.IOException:过早的EOF

时间:2011-11-27 14:46:13

标签: java eof jbpm

我正在尝试访问uniprot网站以检索蛋白质序列列表,并将其配置文件作为XML文件。文件很大。我正在使用JBPM全包附带的eclipse。另外,我在虚拟盒子下使用ubuntu。现在当我运行我的代码时,我得到了这个堆栈跟踪:

 java.io.IOException: Premature EOF
    at sun.net.www.http.ChunkedInputStream.fastRead(ChunkedInputStream.java:234)
    at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:662)
    at java.io.FilterInputStream.read(FilterInputStream.java:116)
    at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2512)
    at edu.uga.uniprot.amna.QueryExecuter.ExecuteQuery(QueryExecuter.java:40)
    at edu.uga.uniprot.amna.Uniprot.getProteenStringByDFamily(Uniprot.java:40)
    at edu.uga.uniprot.amna.Uniprot.getProteensByDFamily(Uniprot.java:55)
    at org.drools.bpmn2.Process_org_drools_bpmn2_Hello_World_0.action4(Process_org_drools_bpmn2_Hello_World_0.java:60)
    at org.drools.bpmn2.Process_org_drools_bpmn2_Hello_World_0Action4Invoker.execute(Process_org_drools_bpmn2_Hello_World_0Action4Invoker.java:14)
    at org.jbpm.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:47)
    at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)
    at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)
    at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)
    at org.jbpm.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:49)
    at org.jbpm.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:41)
    at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)
    at org.jbpm.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:35)
    at org.jbpm.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:188)
    at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:302)
    at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:154)
    at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:124)
    at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1095)
    at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:306)
    at com.sample.ProcessTest.main(ProcessTest.java:49)
java.lang.RuntimeException: unable to execute Action
    at org.jbpm.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:49)
    at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)
    at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)
    at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)
    at org.jbpm.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:49)
    at org.jbpm.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:41)
    at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)
    at org.jbpm.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:35)
    at org.jbpm.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:188)
    at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:302)
    at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:154)
    at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:124)
    at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1095)
    at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:306)
    at com.sample.ProcessTest.main(ProcessTest.java:49)
Caused by: java.lang.NullPointerException
    at java.io.StringReader.<init>(StringReader.java:33)
    at edu.uga.uniprot.amna.Uniprot.loadProteenFromString(Uniprot.java:117)
    at edu.uga.uniprot.amna.Uniprot.getProteensByDFamily(Uniprot.java:58)
    at org.drools.bpmn2.Process_org_drools_bpmn2_Hello_World_0.action4(Process_org_drools_bpmn2_Hello_World_0.java:60)
    at org.drools.bpmn2.Process_org_drools_bpmn2_Hello_World_0Action4Invoker.execute(Process_org_drools_bpmn2_Hello_World_0Action4Invoker.java:14)
    at org.jbpm.workflow.instance.node.ActionNodeInstance.internalTrigger(ActionNodeInstance.java:47)
    ... 14 more

任何人都可以帮助解决此错误或导致错误的原因吗?

以下是生成错误的代码:

public static String ExecuteQuery(String queryURL, boolean writeFile) { 

    URL url;

    try {

        System.out.println("Strat getting Data"); 

        String output = ""; 

        int read; 

        RandomAccessFile  file = null; 

        url = new URL(queryURL);

        HttpURLConnection connection =

                (HttpURLConnection) url.openConnection();



        connection.setRequestProperty("Content-Type", "application/xml");

        connection.connect();       



        //read the result from the server

        if(writeFile == true) { 

            file = new RandomAccessFile(fileName, "rw");

        } 

        InputStream stream = connection.getInputStream();

        byte[] buffer = new byte[1024]; 

        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));



        while((read = stream.read(buffer, 0, 1024)) != -1) { 

            //System.out.println(new String(buffer)); 

            output = output + new String(buffer).substring(0, read); 

            if(writeFile == true) { 

                file.write(buffer, 0, read); 

            } 

            buffer = new byte[1024]; 

        }

        System.out.println(output); 

        return output; 

    } catch (MalformedURLException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

    } catch (IOException e) {

        // TODO Auto-generated catch block

        e.printStackTrace();

    } 

    return null; 

}

3 个答案:

答案 0 :(得分:1)

此错误是由您将空值传递到Uniprot.java第117行的新StringReader()引起的。

你可以通过stacktrace看到这个:

Caused by: java.lang.NullPointerException
    at java.io.StringReader.<init>(StringReader.java:33)
    at edu.uga.uniprot.amna.Uniprot.loadProteenFromString(Uniprot.java:117)
    at edu.uga.uniprot.amna.Uniprot.getProteensByDFamily(Uniprot.java:58)

StringReader的构造函数如下:

public StringReader(String   s) {
    this.str = s;
    this.length = s.length(); // line 33
}

查看更多StringReader

答案 1 :(得分:1)

如果您尝试在一个http连接中下载大量uniprot条目,则可能会使您的http连接死亡。我建议您查看http://www.uniprot.org/faq/28#retrieving_entries_via_queries并使用http请求中的偏移量和限制参数来限制您尝试一次性检索的条目数。

下载非常大的结果集时,动态http请求往往会失败。另一种选择是通过ftp下载所有条目并处理下载文件。请参阅UniProt FTP site

答案 2 :(得分:-3)

我终于解决了由于快速读取连接速度慢而导致的问题。一旦我添加了System.out.println(new String(buffer)),它就可以了。

println语句会降低读取操作的速度并使其与连接速度兼容。

我希望这对任何面临同样问题的人都有帮助。