for (int i = 0; i < poolSize; i++) { DOM_BUILDERS.offer( new PoolDOMBuilder(POOL_GENERATION.get(), getDocumentBuilder()));
/** * Builds a Document with a DocumentBuilder from the pool * * @since Apache Tika 1.19.1 * @param uriString uriString to process * @return a document * @throws TikaException * @throws IOException * @throws SAXException */ public static Document buildDOM(String uriString) throws TikaException, IOException, SAXException { PoolDOMBuilder builder = acquireDOMBuilder(); try { return builder.getDocumentBuilder().parse(uriString); } finally { releaseDOMBuilder(builder); } }
/** * Return parser to the pool for reuse. * * @param builder builder to return */ private static void releaseDOMBuilder(PoolDOMBuilder builder) { if (builder.getPoolGeneration() != POOL_GENERATION.get()) { return; } try { builder.reset(); } catch (UnsupportedOperationException e) { //ignore } try { DOM_READ_WRITE_LOCK.readLock().lock(); //if there are extra parsers (e.g. after a reset of the pool to a smaller size), // this parser will not be added and will then be gc'd boolean success = DOM_BUILDERS.offer(builder); if (! success) { LOG.warning("DocumentBuilder not taken back into pool. If you haven't resized the pool, this could " + "be a sign that there are more calls to 'acquire' than to 'release'"); } } finally { DOM_READ_WRITE_LOCK.readLock().unlock(); } }
for (int i = 0; i < poolSize; i++) { DOM_BUILDERS.offer( new PoolDOMBuilder(POOL_GENERATION.get(), getDocumentBuilder()));
/** * This checks context for a user specified {@link DocumentBuilder}. * If one is not found, this reuses a DocumentBuilder from the pool. * * @since Apache Tika 1.19 * @param is InputStream to parse * @param context context to use * @return a document * @throws TikaException * @throws IOException * @throws SAXException */ public static Document buildDOM(InputStream is, ParseContext context) throws TikaException, IOException, SAXException { DocumentBuilder builder = context.get(DocumentBuilder.class); PoolDOMBuilder poolBuilder = null; if (builder == null) { poolBuilder = acquireDOMBuilder(); builder = poolBuilder.getDocumentBuilder(); } try { return builder.parse(is); } finally { if (poolBuilder != null) { releaseDOMBuilder(poolBuilder); } } }
/** * Return parser to the pool for reuse. * * @param builder builder to return */ private static void releaseDOMBuilder(PoolDOMBuilder builder) { if (builder.getPoolGeneration() != POOL_GENERATION.get()) { return; } try { builder.reset(); } catch (UnsupportedOperationException e) { //ignore } try { DOM_READ_WRITE_LOCK.readLock().lock(); //if there are extra parsers (e.g. after a reset of the pool to a smaller size), // this parser will not be added and will then be gc'd boolean success = DOM_BUILDERS.offer(builder); if (! success) { LOG.warning("DocumentBuilder not taken back into pool. If you haven't resized the pool, this could " + "be a sign that there are more calls to 'acquire' than to 'release'"); } } finally { DOM_READ_WRITE_LOCK.readLock().unlock(); } }
/** * Builds a Document with a DocumentBuilder from the pool * * @since Apache Tika 1.19.1 * * @return a document * @throws TikaException * @throws IOException * @throws SAXException */ public static Document buildDOM(InputStream is) throws TikaException, IOException, SAXException { PoolDOMBuilder builder = acquireDOMBuilder(); try { return builder.getDocumentBuilder().parse(is); } finally { releaseDOMBuilder(builder); } }
/** * Builds a Document with a DocumentBuilder from the pool * * @since Apache Tika 1.19.1 * @param uriString uriString to process * @return a document * @throws TikaException * @throws IOException * @throws SAXException */ public static Document buildDOM(String uriString) throws TikaException, IOException, SAXException { PoolDOMBuilder builder = acquireDOMBuilder(); try { return builder.getDocumentBuilder().parse(uriString); } finally { releaseDOMBuilder(builder); } }
/** * This checks context for a user specified {@link DocumentBuilder}. * If one is not found, this reuses a DocumentBuilder from the pool. * * @since Apache Tika 1.19 * @param is InputStream to parse * @param context context to use * @return a document * @throws TikaException * @throws IOException * @throws SAXException */ public static Document buildDOM(InputStream is, ParseContext context) throws TikaException, IOException, SAXException { DocumentBuilder builder = context.get(DocumentBuilder.class); PoolDOMBuilder poolBuilder = null; if (builder == null) { poolBuilder = acquireDOMBuilder(); builder = poolBuilder.getDocumentBuilder(); } try { return builder.parse(is); } finally { if (poolBuilder != null) { releaseDOMBuilder(poolBuilder); } } }
/** * Builds a Document with a DocumentBuilder from the pool * * @since Apache Tika 1.19.1 * * @return a document * @throws TikaException * @throws IOException * @throws SAXException */ public static Document buildDOM(InputStream is) throws TikaException, IOException, SAXException { PoolDOMBuilder builder = acquireDOMBuilder(); try { return builder.getDocumentBuilder().parse(is); } finally { releaseDOMBuilder(builder); } }