@Test public void testSerialParsing() throws Exception { try (ForkParser parser = new ForkParser(ForkParserTest.class.getClassLoader(), new ForkTestParser())) { ParseContext context = new ParseContext(); for (int i = 0; i < 10; i++) { ContentHandler output = new BodyContentHandler(); InputStream stream = new ByteArrayInputStream(new byte[0]); parser.parse(stream, output, new Metadata(), context); assertEquals("Hello, World!", output.toString().trim()); } } }
public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (stream == null) { throw new NullPointerException("null stream"); } Throwable t; boolean alive = false; ForkClient client = acquireClient(); try { ContentHandler tee = (handler instanceof AbstractRecursiveParserWrapperHandler) ? handler : new TeeContentHandler( handler, new MetadataContentHandler(metadata)); t = client.call("parse", stream, tee, metadata, context); alive = true; } catch (TikaException te) { alive = true; throw te; } catch (IOException e) { throw new TikaException( "Failed to communicate with a forked parser process." + " The process has most likely crashed due to some error" + " like running out of memory. A new process will be" + " started for the next parsing request.", e); } finally { releaseClient(client, alive); } if (t instanceof IOException) { throw (IOException) t; } else if (t instanceof SAXException) { throw (SAXException) t; } else if (t instanceof TikaException) { throw (TikaException) t; } else if (t != null) { throw new TikaException( "Unexpected error in forked server process", t); } }
ForkParser extends AbstractParser implements Closeable { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (stream == null) { throw new NullPointerException("null stream"); } Throwable t; boolean alive = false; ForkClient client = acquireClient(); try { ContentHandler tee = (handler instanceof AbstractRecursiveParserWrapperHandler) ? handler : new TeeContentHandler( handler, new MetadataContentHandler(metadata)); t = client.call("parse", stream, tee, metadata, context); alive = true; } catch (TikaException te) { alive = true; throw te; } catch (IOException e) { throw new TikaException( "Failed to communicate with a forked parser process." + " The process has most likely crashed due to some error" + " like running out of memory. A new process will be" + " started for the next parsing request.", e); } finally { releaseClient(client, alive); } if (t instanceof IOException) { throw (IOException) t; } else if (t instanceof SAXException) { throw (SAXException) t; } else if (t instanceof TikaException) { throw (TikaException) t; } else if (t != null) { throw new TikaException( "Unexpected error in forked server process", t); } } }
ForkParser extends AbstractParser implements Closeable { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (stream == null) { throw new NullPointerException("null stream"); } Throwable t; boolean alive = false; ForkClient client = acquireClient(); try { ContentHandler tee = (handler instanceof AbstractRecursiveParserWrapperHandler) ? handler : new TeeContentHandler( handler, new MetadataContentHandler(metadata)); t = client.call("parse", stream, tee, metadata, context); alive = true; } catch (TikaException te) { alive = true; throw te; } catch (IOException e) { throw new TikaException( "Failed to communicate with a forked parser process." + " The process has most likely crashed due to some error" + " like running out of memory. A new process will be" + " started for the next parsing request.", e); } finally { releaseClient(client, alive); } if (t instanceof IOException) { throw (IOException) t; } else if (t instanceof SAXException) { throw (SAXException) t; } else if (t instanceof TikaException) { throw (TikaException) t; } else if (t != null) { throw new TikaException( "Unexpected error in forked server process", t); } } ForkParser(Path tikaBin, ParserFactoryFactory factoryFactory);  ForkParser(Path tikaBin, ParserFactoryFactory parserFactoryFactory, ClassLoader classLoader);  ForkParser(ClassLoader loader, Parser parser);  ForkParser(ClassLoader loader);  ForkParser(); }
ForkParser extends AbstractParser implements Closeable { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (stream == null) { throw new NullPointerException("null stream"); } Throwable t; boolean alive = false; ForkClient client = acquireClient(); try { ContentHandler tee = (handler instanceof AbstractRecursiveParserWrapperHandler) ? handler : new TeeContentHandler( handler, new MetadataContentHandler(metadata)); t = client.call("parse", stream, tee, metadata, context); alive = true; } catch (TikaException te) { alive = true; throw te; } catch (IOException e) { throw new TikaException( "Failed to communicate with a forked parser process." + " The process has most likely crashed due to some error" + " like running out of memory. A new process will be" + " started for the next parsing request.", e); } finally { releaseClient(client, alive); } if (t instanceof IOException) { throw (IOException) t; } else if (t instanceof SAXException) { throw (SAXException) t; } else if (t instanceof TikaException) { throw (TikaException) t; } else if (t != null) { throw new TikaException( "Unexpected error in forked server process", t); } } ForkParser(Path tikaBin, ParserFactoryFactory factoryFactory);  ForkParser(Path tikaBin, ParserFactoryFactory parserFactoryFactory, ClassLoader classLoader);  ForkParser(ClassLoader loader, Parser parser);  ForkParser(ClassLoader loader);  ForkParser(); synchronized int getPoolSize(); synchronized void setPoolSize(int poolSize); @Deprecated String getJavaCommand(); List<String> getJavaCommandAsList(); void setJavaCommand(List<String> java); @Deprecated void setJavaCommand(String java); Set<MediaType> getSupportedTypes(ParseContext context); void parse(
            InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context); synchronized void close(); void setServerPulseMillis(long serverPulseMillis); void setServerParseTimeoutMillis(long serverParseTimeoutMillis); void setServerWaitTimeoutMillis(long serverWaitTimeoutMillis); void setMaxFilesProcessedPerServer(int maxFilesProcessedPerClient); }
ForkParser extends AbstractParser implements Closeable { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { if (stream == null) { throw new NullPointerException("null stream"); } Throwable t; boolean alive = false; ForkClient client = acquireClient(); try { ContentHandler tee = (handler instanceof AbstractRecursiveParserWrapperHandler) ? handler : new TeeContentHandler( handler, new MetadataContentHandler(metadata)); t = client.call("parse", stream, tee, metadata, context); alive = true; } catch (TikaException te) { alive = true; throw te; } catch (IOException e) { throw new TikaException( "Failed to communicate with a forked parser process." + " The process has most likely crashed due to some error" + " like running out of memory. A new process will be" + " started for the next parsing request.", e); } finally { releaseClient(client, alive); } if (t instanceof IOException) { throw (IOException) t; } else if (t instanceof SAXException) { throw (SAXException) t; } else if (t instanceof TikaException) { throw (TikaException) t; } else if (t != null) { throw new TikaException( "Unexpected error in forked server process", t); } } ForkParser(Path tikaBin, ParserFactoryFactory factoryFactory);  ForkParser(Path tikaBin, ParserFactoryFactory parserFactoryFactory, ClassLoader classLoader);  ForkParser(ClassLoader loader, Parser parser);  ForkParser(ClassLoader loader);  ForkParser(); synchronized int getPoolSize(); synchronized void setPoolSize(int poolSize); @Deprecated String getJavaCommand(); List<String> getJavaCommandAsList(); void setJavaCommand(List<String> java); @Deprecated void setJavaCommand(String java); Set<MediaType> getSupportedTypes(ParseContext context); void parse(
            InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context); synchronized void close(); void setServerPulseMillis(long serverPulseMillis); void setServerParseTimeoutMillis(long serverParseTimeoutMillis); void setServerWaitTimeoutMillis(long serverWaitTimeoutMillis); void setMaxFilesProcessedPerServer(int maxFilesProcessedPerClient);  }