//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public opennlp.tools.parser.Parse read() throws java.io.IOException
        public override Parse read()
        {
            if (parses.Count == 0)
            {
                sbyte[] xmlbytes = samples.read();

                if (xmlbytes != null)
                {
                    IList <Parse> producedParses = new List <Parse>();
                    try
                    {
                        saxParser.parse(new ByteArrayInputStream(xmlbytes), new ConstitDocumentHandler(producedParses));
                    }
                    catch (SAXException e)
                    {
                        //TODO update after Java6 upgrade
                        throw (IOException)(new IOException(e.Message)).initCause(e);
                    }

                    parses.AddRange(producedParses);
                }
            }

            if (parses.Count > 0)
            {
                return(parses.Remove(0));
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        public virtual Parse execute()
        {
            try
            {
                Stream inputStream = streamSource.InputStream;

                parser.SaxParserFactory.setFeature(XXE_PROCESSING, enableXxeProcessing);

                if (string.ReferenceEquals(schemaResource, null))
                {   // must be done before parser is created
                    parser.SaxParserFactory.NamespaceAware = false;
                    parser.SaxParserFactory.Validating     = false;
                }

                SAXParser saxParser = parser.SaxParser;
                if (!string.ReferenceEquals(schemaResource, null))
                {
                    saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                    saxParser.setProperty(JAXP_SCHEMA_SOURCE, schemaResource);
                }
                saxParser.parse(inputStream, new ParseHandler(this));
            }
            catch (Exception e)
            {
                throw LOG.parsingFailureException(name_Renamed, e);
            }

            return(this);
        }