示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void close() throws org.maltparser.core.exception.MaltChainedException
        public virtual void close()
        {
            try
            {
                if (reader != null)
                {
                    if (closeStream)
                    {
                        reader.close();
                    }
                    reader = null;
                }
            }
            catch (XMLStreamException e)
            {
                throw new DataFormatException("The XML input file could be closed. ", e);
            }
        }
 /// <summary>
 /// Parses the specified source as an XML file to an in-memory DOM-like structure.
 /// <para>
 /// This parses the specified byte source expecting an XML file format.
 /// The resulting instance can be queried for the root element.
 /// </para>
 /// <para>
 /// This supports capturing attribute references, such as an id/href pair.
 /// Wherever the parser finds an attribute with the specified name, the element is added
 /// to the internal map, accessible by calling <seealso cref="#getReferences()"/>.
 /// </para>
 /// <para>
 /// For example, if one part of the XML has {@code <foo id="fooId">}, the references map will
 /// contain an entry mapping "fooId" to the parsed element {@code <foo>}.
 ///
 /// </para>
 /// </summary>
 /// <param name="source">  the XML source data </param>
 /// <param name="refAttrName">  the attribute name that should be parsed as a reference </param>
 /// <returns> the parsed file </returns>
 /// <exception cref="UncheckedIOException"> if an IO exception occurs </exception>
 /// <exception cref="IllegalArgumentException"> if the file cannot be parsed </exception>
 public static XmlFile of(ByteSource source, string refAttrName)
 {
     ArgChecker.notNull(source, "source");
     return(Unchecked.wrap(() =>
     {
         using (Stream @in = source.openBufferedStream())
         {
             XMLStreamReader xmlReader = xmlInputFactory().createXMLStreamReader(@in);
             try
             {
                 Dictionary <string, XmlElement> refs = new Dictionary <string, XmlElement>();
                 XmlElement root = parse(xmlReader, refAttrName, refs);
                 return new XmlFile(root, refs);
             }
             finally
             {
                 xmlReader.close();
             }
         }
     }));
 }