当前位置: 首页>>代码示例>>Java>>正文


Java ProxyInputStream类代码示例

本文整理汇总了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;
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:49,代码来源:DataStore.java


注:本文中的org.apache.commons.io.input.ProxyInputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。