本文整理汇总了Java中org.apache.commons.io.input.ProxyInputStream类的典型用法代码示例。如果您正苦于以下问题:Java ProxyInputStream类的具体用法?Java ProxyInputStream怎么用?Java ProxyInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProxyInputStream类属于org.apache.commons.io.input包,在下文中一共展示了ProxyInputStream类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInputStream
import org.apache.commons.io.input.ProxyInputStream; //导入依赖的package包/类
/**
* Returns an input stream for the requested file.
*
* After completing the read the stream must be closed. It is not necessary to call the {@link #release()}
* method after reading from the input stream.
*
* Example usage:
*
* DataStore dataStore = new DataStore(...);
* try (InputStream is = dataStore.getInputStream()) {
* // read from is
* } catch (IOException e) {
* ...
* }
*
* @return
* @throws IOException
*/
public InputStream getInputStream() throws IOException {
acquireLock();
try {
isClosed = false;
forWrite = false;
LOG.trace("Starts read '{}'", file);
verifyAndRecover();
InputStream is = new ProxyInputStream(new FileInputStream(file.toFile())) {
@Override
public void close() throws IOException {
if (isClosed) {
return;
}
try {
super.close();
} finally {
release();
isClosed = true;
stream = null;
}
LOG.trace("Finishes read '{}'", file);
}
};
stream = is;
return is;
} catch (Exception ex) {
release();
throw ex;
}
}