本文整理了Java中org.apache.tika.io.IOUtils.closeQuietly()
方法的一些代码示例,展示了IOUtils.closeQuietly()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.closeQuietly()
方法的具体详情如下:
包路径:org.apache.tika.io.IOUtils
类名称:IOUtils
方法名:closeQuietly
[英]Unconditionally close an InputStream
.
Equivalent to InputStream#close(), except any exceptions will be ignored. This is typically used in finally blocks.
[中]无条件关闭InputStream
。
与InputStream#close()等效,但任何异常都将被忽略。这通常用于finally块。
代码示例来源:origin: apache/tika
@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;
}
}
代码示例来源:origin: apache/tika
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;
}
}
代码示例来源:origin: apache/tika
/**
* 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);
}
代码示例来源:origin: apache/tika
public void run() {
try {
IOUtils.copy(stream, new NullOutputStream());
} catch (IOException e) {
} finally {
IOUtils.closeQuietly(stream);
}
}
};
代码示例来源:origin: apache/tika
IOUtils.closeQuietly(reader);
IOUtils.closeQuietly(stream);
代码示例来源:origin: apache/tika
LOG.warn("IOException trying to read: '" + langCode + "'");
} finally {
IOUtils.closeQuietly(is);
代码示例来源:origin: apache/tika
IOUtils.closeQuietly(tikaInputStream);
IOUtils.closeQuietly(outputStream);
IOUtils.closeQuietly(stdErrOutputStream);
if (process.exitValue() != 0) {
throw new TikaException("There was an error executing the command line" +
代码示例来源:origin: apache/tika
throw new ExtractReaderException(ExtractReaderException.TYPE.EXTRACT_PARSE_EXCEPTION);
} finally {
IOUtils.closeQuietly(reader);
IOUtils.closeQuietly(is);
代码示例来源:origin: apache/tika
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);
}
}
}
代码示例来源:origin: apache/tika
IOUtils.closeQuietly(tis);
IOUtils.closeQuietly(ocStream);
代码示例来源:origin: info.magnolia/magnolia-4-5-migration
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);
}
}
代码示例来源:origin: org.apache.tika/tika-core
public void run() {
try {
IOUtils.copy(stream, new NullOutputStream());
} catch (IOException e) {
} finally {
IOUtils.closeQuietly(stream);
}
}
};
代码示例来源:origin: basis-technology-corp/Java-readability
/** {@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);
}
}
}
代码示例来源:origin: org.apache.tika/tika-core
IOUtils.closeQuietly(reader);
IOUtils.closeQuietly(stream);
代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-external
public void run() {
try {
IOUtils.copy(stream, new NullOutputStream());
} catch (IOException e) {
} finally {
IOUtils.closeQuietly(stream);
}
}
};
代码示例来源:origin: org.apache.tika/tika-parsers
/**
* 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);
}
代码示例来源:origin: com.github.lafa.tikaNoExternal/tika-parsers
/**
* 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);
}
代码示例来源:origin: hibernate/hibernate-search
/**
* 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 );
}
}
代码示例来源:origin: org.infinispan/infinispan-embedded-query
/**
* 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 );
}
}
代码示例来源:origin: org.artificer/artificer-repository-hibernate
@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 );
}
}
内容来源于网络,如有侵权,请联系作者删除!