Marshal a {@link Document} to {@link InputStream}

@param is the InputStream containing XML data
@return {@link Document} containg the XML data
@throws SAXException
@throws IOException
436801
public static Document toDocument(InputStream is) throws MarshalException {
		try {
			return newDocumentBuilder().parse(is);
		} catch (SAXException e) {
			IfmapJLog.error(e.getMessage());
			throw new MarshalException(e.getMessage());
		} catch (IOException e) {
			IfmapJLog.error(e.getMessage());
			throw new MarshalException(e.getMessage());
		}
	}
5782
private void processFile(InputStream is) throws MPXJException
   {
      int line = 1;

      try
      {
         //
         // Test the header and extract the separator. If this is successful,
         // we reset the stream back as far as we can. The design of the
         // BufferedInputStream class means that we can't get back to character
         // zero, so the first record we will read will get "RMHDR" rather than
         // "ERMHDR" in the first field position.
         //
         BufferedInputStream bis = new BufferedInputStream(is);
         byte[] data = new byte[6];
         data[0] = (byte) bis.read();
         bis.mark(1024);
         bis.read(data, 1, 5);

         if (!new String(data).equals("ERMHDR"))
         {
            throw new MPXJException(MPXJException.INVALID_FILE);
         }

         bis.reset();

         InputStreamReader reader = new InputStreamReader(bis, getCharset());
         Tokenizer tk = new ReaderTokenizer(reader);
         tk.setDelimiter('\t');
         List<String> record = new ArrayList<String>();

         while (tk.getType() != Tokenizer.TT_EOF)
         {
            readRecord(tk, record);
            if (!record.isEmpty())
            {
               if (processRecord(record))
               {
                  break;
               }
            }
            ++line;
         }
      }

      catch (Exception ex)
      {
         throw new MPXJException(MPXJException.READ_ERROR + " (failed at line " + line + ")", ex);
      }
   }
34013
public static <T> void marshal(T obj, OutputStream s) throws JAXBException {
    JAXBContext ctx = JAXBContext.newInstance(obj.getClass());
    Marshaller m = ctx.createMarshaller();
    m.marshal(obj, s);
  }
728237
public static byte[] toByteArray(InputStream is) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        try {
            byte[] b = new byte[BUFFER_SIZE];
            int n = 0;
            while ((n = is.read(b)) != -1) {
                output.write(b, 0, n);
            }
            return output.toByteArray();
        } finally {
            output.close();
        }
    }
477903
public static Element parse(InputSource source) throws IOException
   {
      try
      {
         Document doc;
         DocumentBuilder builder = getDocumentBuilder();
         synchronized (builder) //synchronize to prevent concurrent parsing on the same DocumentBuilder
         {
            doc = builder.parse(source);
         }
         return doc.getDocumentElement();
      }
      catch (SAXException se)
      {
         throw new IOException(se.toString());
      }
      finally
      {
         InputStream is = source.getByteStream();
         if (is != null)
         {
            is.close();
         }
         Reader r = source.getCharacterStream();
         if (r != null)
         {
            r.close();
         }
      }
   }
849186
public static void parse(DocListener document, InputSource is, String tagmap) {
        XmlParser p = new XmlParser();
        p.go(document, is, tagmap);
    }
363010
public static XPathUtils newXPath(final InputStream is)
            throws SAXException, IOException {
        final XPathFactory xpfactory = XPathFactory.newInstance();
        final XPath xPath = xpfactory.newXPath();
        final Document doc = XmlUtils.toDoc(is);
        return new XPathUtils(xPath, doc);
    }
369710
public static Node read(InputStream inputStream) throws XmlException
    {
        try
        {
            DocumentBuilderFactory documentBuilderFactory = 
                DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder = 
                documentBuilderFactory.newDocumentBuilder();
            Document document = documentBuilder.parse(inputStream);
            Node node = document.getDocumentElement();
            return node;
        } 
        catch (ParserConfigurationException canNotHappen)
        {
            // Can not happen with a default configuration
            throw new XmlException("Could not create parser", canNotHappen);
        } 
        catch (SAXException e)
        {
            throw new XmlException("XML parsing error", e);
        }
        catch (IOException e)
        {
            throw new XmlException("IO error while reading XML", e);
        }

    }
629383
public final void parse(InputStream stream) throws IOException {

        // all XML exceptions are wrapped by IOExceptions
        try {

            // setup a namespace aware SAXParserFactory
            SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
            saxParserFactory.setNamespaceAware(true);

            // parse the input stream
            SAXParser parser = saxParserFactory.newSAXParser();
            parser.parse(stream, this);

        } catch (ParserConfigurationException e) {
            throw new IOException(e);
        } catch (SAXException e) {
            throw new IOException(e);
        }

    }
917577
public PackageDescr read(final InputStream inputStream) throws SAXException,
                                                           IOException {
        this.packageDescr = (PackageDescr) this.parser.read( inputStream );
        return this.packageDescr;
    }
135824
public static Element parse(InputStream xmlStream, DocumentBuilder builder) throws IOException
   {
      try
      {
         Document doc;
         synchronized (builder) //synchronize to prevent concurrent parsing on the same DocumentBuilder
         {
            doc = builder.parse(xmlStream);
         }
         return doc.getDocumentElement();
      }
      catch (SAXException se)
      {
         throw new IOException(se.toString());
      }
      finally
      {
         xmlStream.close();
      }
   }
477785
public static SOAPMessage createSoapFromStream(Map<String,String> headers, InputStream is){
        return createSoapFromStream(null,headers,is);
    }
229095
private Document getDocument(FileResource resource) throws SAXException, IOException {
        return documentBuilder.parse(resource.getFile());
    }
93575
private static Document _loadDocument(InputStream is) throws SAXException, IOException {
	InputSource source = new InputSource(is);

	return XMLUtil.parse(source, null, false);
    }
1095259
private void write(String s)
            throws SAXException {
        try {
            out.write(s);
            out.flush();
        } catch (IOException ioException) {
            throw new SAXParseException("I/O error",
                    documentLocator,
                    ioException);
        }
    }
357899
public void go(DocListener document, InputSource is, String tagmap) {
        try {
            parser.parse(is, new SAXmyHandler(document, new TagMap(tagmap)));
        }
        catch(SAXException se) {
            throw new ExceptionConverter(se);
        }
        catch(IOException ioe) {
            throw new ExceptionConverter(ioe);
        }
    }
141596
private void checkAsXML(InputSource is) throws IOException, SAXException {
        xmlParser.setCharacterHandler(sourceCode);
        sourceCode.initialize(is);
        try {
            xmlReader.parse(is);
        } catch (SAXParseException e) {
        } catch (FatalSAXException e) {
        }
    }