@Override public int read() throws IOException { int c = streams[currentStreamIndex].read(); if (c < 0) { IOUtils.closeQuietly(streams[currentStreamIndex]); while (currentStreamIndex < streams.length-1) { currentStreamIndex++; int tmpC = streams[currentStreamIndex].read(); if (tmpC < 0) { IOUtils.closeQuietly(streams[currentStreamIndex]); } else { return tmpC; } } return -1; } return c; } }
protected boolean hasTestLanguage(String language) { InputStream stream = LanguageDetectorTest.class.getResourceAsStream("/language-tests/" + language + ".test"); if (stream != null) { IOUtils.closeQuietly(stream); return true; } else { return false; } }
/** * Creates OpenNLP name finder * @param nameType the entity type recognised by the given NER model * @param nerModelPath path to ner model */ public OpenNLPNameFinder(String nameType, String nerModelPath) { this.nameTypes = Collections.singleton(nameType); this.nameType = nameType; InputStream nerModelStream = getClass().getClassLoader().getResourceAsStream(nerModelPath); try { if (nerModelStream != null){ TokenNameFinderModel model = new TokenNameFinderModel(nerModelStream); this.nameFinder = new NameFinderME(model); this.available = true; } else { LOG.warn("Couldn't find model from {} using class loader", nerModelPath); } } catch (IOException e) { LOG.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(nerModelStream); } LOG.info("{} NER : Available for service ? {}", nameType, available); }
public void run() { try { IOUtils.copy(stream, new NullOutputStream()); } catch (IOException e) { } finally { IOUtils.closeQuietly(stream); } } };
IOUtils.closeQuietly(reader); IOUtils.closeQuietly(stream);
LOG.warn("IOException trying to read: '" + langCode + "'"); } finally { IOUtils.closeQuietly(is);
IOUtils.closeQuietly(tikaInputStream); IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(stdErrOutputStream); if (process.exitValue() != 0) { throw new TikaException("There was an error executing the command line" +
throw new ExtractReaderException(ExtractReaderException.TYPE.EXTRACT_PARSE_EXCEPTION); } finally { IOUtils.closeQuietly(reader); IOUtils.closeQuietly(is);
private void handleCompoundContent(OleBlob.CompoundContent cc, XHTMLContentHandler xhtml) throws IOException, SAXException, TikaException { InputStream is = null; POIFSFileSystem fileSystem = null; try { try { is = cc.getStream(); } catch (IOException e) { EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata); return; } try { fileSystem = new POIFSFileSystem(is); } catch (Exception e) { EmbeddedDocumentUtil.recordEmbeddedStreamException(e, parentMetadata); return; } handleEmbeddedOfficeDoc(fileSystem.getRoot(), xhtml); } finally { if (fileSystem != null) { try { fileSystem.close(); } catch (IOException e) { //swallow } } if (is != null) { IOUtils.closeQuietly(is); } } }
IOUtils.closeQuietly(tis); IOUtils.closeQuietly(ocStream);
protected void loadDefaults() { InputStream is = null; try { if (defaults != null) { String[] pathsToBoostraps = ClasspathResourcesUtil.findResources("/"+defaults); if(pathsToBoostraps!=null && pathsToBoostraps.length>0) { is = PersistentMapService.class.getResourceAsStream(pathsToBoostraps[0]); getInMemory().load(is); } else { log.warn("Cannot load defaults from resource " + defaults); } } } catch (Exception ex) { log.error("Cannot initialize persistent map from resource: " + defaults); log.debug("Problem reading defaults for persistent map from resource: " + defaults, ex); } finally { IOUtils.closeQuietly(is); } }
public void run() { try { IOUtils.copy(stream, new NullOutputStream()); } catch (IOException e) { } finally { IOUtils.closeQuietly(stream); } } };
/** {@inheritDoc} */ @Override public String readPage(String url) throws PageReadException { int lastSlash = url.replace("\\", "/").lastIndexOf('/'); File testFile = new File(baseDirectory, url.substring(lastSlash + 1)); LOG.info("Reading " + testFile + " for " + url); FileInputStream fis = null; try { try { fis = new FileInputStream(testFile); return readContent(fis, null); } catch (IOException e) { throw new PageReadException("Failed to read " + url, e); } } finally { if (fis != null) { IOUtils.closeQuietly(fis); } } }
IOUtils.closeQuietly(reader); IOUtils.closeQuietly(stream);
public void run() { try { IOUtils.copy(stream, new NullOutputStream()); } catch (IOException e) { } finally { IOUtils.closeQuietly(stream); } } };
/** * Creates OpenNLP name finder * @param nameType the entity type recognised by the given NER model * @param nerModelPath path to ner model */ public OpenNLPNameFinder(String nameType, String nerModelPath) { this.nameTypes = Collections.singleton(nameType); this.nameType = nameType; InputStream nerModelStream = getClass().getClassLoader().getResourceAsStream(nerModelPath); try { if (nerModelStream != null){ TokenNameFinderModel model = new TokenNameFinderModel(nerModelStream); this.nameFinder = new NameFinderME(model); this.available = true; } else { LOG.warn("Couldn't find model from {} using class loader", nerModelPath); } } catch (IOException e) { LOG.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(nerModelStream); } LOG.info("{} NER : Available for service ? {}", nameType, available); }
/** * Creates OpenNLP name finder * @param nameType the entity type recognised by the given NER model * @param nerModelPath path to ner model */ public OpenNLPNameFinder(String nameType, String nerModelPath) { this.nameTypes = Collections.singleton(nameType); this.nameType = nameType; InputStream nerModelStream = getClass().getClassLoader().getResourceAsStream(nerModelPath); try { if (nerModelStream != null){ TokenNameFinderModel model = new TokenNameFinderModel(nerModelStream); this.nameFinder = new NameFinderME(model); this.available = true; } else { LOG.warn("Couldn't find model from {} using class loader", nerModelPath); } } catch (IOException e) { LOG.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(nerModelStream); } LOG.info("{} NER : Available for service ? {}", nameType, available); }
/** * Opens an input stream for the given blob, byte array, file or URI and returns its contents. */ private String getFieldValue(String name, Object value, Metadata metadata) { InputStream in = getInputStreamForData( value ); try { ParseContext parseContext = parseContextProvider.getParseContext( name, value ); StringWriter writer = new StringWriter(); WriteOutContentHandler contentHandler = new WriteOutContentHandler( writer ); parser.parse( in, contentHandler, metadata, parseContext ); return writer.toString(); } catch (Exception e) { throw log.unableToParseDocument( e ); } finally { closeQuietly( in ); } }
/** * Opens an input stream for the given blob, byte array, file or URI and returns its contents. */ private String getFieldValue(String name, Object value, Metadata metadata) { InputStream in = getInputStreamForData( value ); try { ParseContext parseContext = parseContextProvider.getParseContext( name, value ); StringWriter writer = new StringWriter(); WriteOutContentHandler contentHandler = new WriteOutContentHandler( writer ); parser.parse( in, contentHandler, metadata, parseContext ); return writer.toString(); } catch (Exception e) { throw log.unableToParseDocument( e ); } finally { closeQuietly( in ); } }
@Override public void set(String name, Object value, Document document, LuceneOptions luceneOptions) { if ( value == null ) { // throw new IllegalArgumentException( "null cannot be passed to Tika bridge" ); return; } InputStream in = getInputStreamForData( value ); try { Metadata metadata = metadataProcessor.prepareMetadata(); ParseContext parseContext = parseContextProvider.getParseContext( name, value ); StringWriter writer = new StringWriter(); WriteOutContentHandler contentHandler = new WriteOutContentHandler( writer ); PARSER.parse( in, contentHandler, metadata, parseContext ); luceneOptions.addFieldToDocument( name, writer.toString(), document ); // allow for optional indexing of metadata by the user metadataProcessor.set( name, value, document, luceneOptions, metadata ); } catch ( Exception e ) { // throw log.unableToParseDocument( e ); log.warn("Tika was unable to parse the document -- full-text search may not work properly.", e); } finally { closeQuietly( in ); } }