@SuppressWarnings("unchecked") private JaxbTypedObject<T> unmarshall(InputStream stream) throws JAXBException, XMLStreamException { Unmarshaller u = context.createUnmarshaller(); if (DEBUG) { stream = debugInput(stream); } T object = (T) u.unmarshal(inputFactory.createXMLEventReader(stream)); if (object == null) { return null; } return typedObjectFactory.create(object); }
/** * Reads a SBML document from the given {@code stream}. * * @param stream * @param listener * @return * @throws XMLStreamException */ public SBMLDocument readSBMLFromStream(InputStream stream, TreeNodeChangeListener listener) throws XMLStreamException { WstxInputFactory inputFactory = new WstxInputFactory(); XMLEventReader xmlEventReader = inputFactory.createXMLEventReader(stream); return (SBMLDocument) readXMLFromXMLEventReader(xmlEventReader, listener); }
/** * Reads a XML document from the given {@code stream}. It need to be a self contain part of * an SBML document. * * @param stream * @param listener * @return * @throws XMLStreamException */ private Object readXMLFromStream(InputStream stream, TreeNodeChangeListener listener) throws XMLStreamException { WstxInputFactory inputFactory = new WstxInputFactory(); // see https://groups.google.com/d/msg/jsbml-development/cckEJPYNzQY/5ynmIbqNCAAJ for why we did set this value try { inputFactory.setProperty(WstxInputProperties.P_MAX_ELEMENT_DEPTH, 5000); } catch(IllegalArgumentException e) { // do nothing - the XML libraries used do not support this property for some reason } XMLEventReader xmlEventReader = inputFactory.createXMLEventReader(stream); return readXMLFromXMLEventReader(xmlEventReader, listener); }