View Javadoc

1   package fr.ove.openmath.mathematica;
2   
3   import java.io.*;
4   import fr.inria.openmath.omapi.*;
5   import fr.inria.openmath.omapi.implementation.*;
6   import fr.ove.openmath.mathematica.omparser.PipeParserHandler;
7   
8   public class ResponseReader {
9       /***
10      * The XML parser.
11      */
12      private XMLParser parser;
13      
14      /***
15      * The handler for the parser.
16      */
17      private PipeParserHandler handler = new PipeParserHandler();
18      
19      /***
20      * The Constructor.
21      */
22      public ResponseReader() {
23          parser = new XMLParser(handler);
24      }
25      
26      /***
27      * read the result from the input stream.
28      */
29      public String read(InputStream inputStream) {
30          try {
31              parser.initParse(inputStream);
32                      
33              int dispo = 0;
34              while ((dispo = inputStream.available()) == 0) {
35                  try {
36                      Thread.sleep(100);
37                  }
38                  catch (Exception e) {
39                  }
40              }
41                      
42              parser.parseObject(inputStream);
43                      
44              return handler.getOmObjectParsed();
45          }
46          catch (Exception e) {
47              e.printStackTrace();
48              return null;
49          }
50      }
51  }