示例#1
0
  /**
   * Attempts to read a ComplexDataObject from the Reader
   *
   * @return A parsed ComplexDataObject
   * @throws IOException
   */
  public ComplexDataObject read() throws IOException {
    ComplexDataObject obj = null;

    if (!finished) {
      try {
        obj = ioSource.readObject(element);
      } catch (IOException ioEx) {

        // If we're using the XML source, the underlying SAXParser can helpfully close the stream
        // when it finished parsing the previous element, presumably because it assumes the document
        // is well-formed (ie only one per file)
        if (ioSource instanceof XMLSource) {
          // Find the root cause
          Throwable ex = ioEx;
          while (ex.getCause() != null) {
            ex = ex.getCause();
          }
          if (ex instanceof IOException && ex.getMessage() == "Stream closed") {
            // Sigh. That looks like that's what's happened.
            obj = null;
          } else {
            // Rethrow
            throw ioEx;
          }
        } else {
          // Rethrow
          throw ioEx;
        }
      } finally {
        if (obj == null) {
          finished = true;
        }
      }
    }

    return obj;
  }
示例#2
0
 public Reader getReader() {
   return ioSource.getReader();
 }
示例#3
0
 /**
  * Sets the reader that we'll consume data from
  *
  * @param reader
  */
 public void setReader(Reader reader) {
   ioSource.setReader(reader);
 }