Java 类java.io.Closeable 实例源码

项目:gemini.blueprint    文件:ClassUtilsTest.java   
public void testAppContextClassHierarchy() {
    Class<?>[] clazz =
            ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES);

       //Closeable.class,
    Class<?>[] expected =
            new Class<?>[] { OsgiBundleXmlApplicationContext.class,
                    AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class,
                    AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class,
                    DefaultResourceLoader.class, ResourceLoader.class,
                    AutoCloseable.class,
                    DelegatedExecutionOsgiBundleApplicationContext.class,
                    ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class,
                    ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class,
                    HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class,
                    MessageSource.class, BeanFactory.class, DisposableBean.class };

    assertTrue(compareArrays(expected, clazz));
}
项目:hibernate-types    文件:AbstractTest.java   
@After
public void destroy() {
    if (nativeHibernateSessionFactoryBootstrap()) {
        sf.close();
    } else {
        emf.close();
    }
    for (Closeable closeable : closeables) {
        try {
            closeable.close();
        } catch (IOException e) {
            LOGGER.error("Failure", e);
        }
    }
    closeables.clear();
}
项目:hibernate-types    文件:AbstractTest.java   
@After
public void destroy() {
    if (nativeHibernateSessionFactoryBootstrap()) {
        sf.close();
    } else {
        emf.close();
    }
    for (Closeable closeable : closeables) {
        try {
            closeable.close();
        } catch (IOException e) {
            LOGGER.error("Failure", e);
        }
    }
    closeables.clear();
}
项目:oscm    文件:DatabaseUpgradeHandlerTest.java   
@Test
public void getSQLCommandsFromFile_closeStream_ioException()
        throws Exception {
    // given
    handler = spy(new DatabaseUpgradeHandler());

    // when
    try {
        handler.getSQLCommandsFromFile(new File("unknownpath"));
        fail();
    } catch (FileNotFoundException e) {

        // then
        assertNotNull(e);
        verify(handler, times(3)).closeStream(any(Closeable.class));
    }
}
项目:openjdk-jdk10    文件:DocumentBuilderFactoryTest.java   
/**
 * Test the default functionality of schema support method. In
 * this case the schema source property is set.
 * @throws Exception If any errors occur.
 */
@Test(dataProvider = "schema-source")
public void testCheckSchemaSupport2(Object schemaSource) throws Exception {
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);
        dbf.setNamespaceAware(true);
        dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                W3C_XML_SCHEMA_NS_URI);
        dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", schemaSource);
        MyErrorHandler eh = MyErrorHandler.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setErrorHandler(eh);
        db.parse(new File(XML_DIR, "test1.xml"));
        assertFalse(eh.isErrorOccured());
    } finally {
        if (schemaSource instanceof Closeable) {
            ((Closeable) schemaSource).close();
        }
    }

}
项目:JRF    文件:JRFProvider.java   
private void handleClose(MsgClose m) throws IOException {
    int fileID = m.getFileID();
    log.info(getName()+": Request close file "+fileID);
    Closeable stream;
    synchronized (localIS) {
        stream = localIS.get(m.getFileID());
    }
    if (stream == null) { // Maybe an OutputStream?
        synchronized (localOS) {
            stream = localOS.get(m.getFileID());
        }
    }
    if (stream == null) { // File descriptor not found
        log.warning(getName()+": Local file ID "+fileID+" not found");
    } else {
        try {
            stream.close();
            log.fine(getName()+": Closed file "+fileID);
        } catch (IOException e) { // Exception during skip
            log.warning(getName()+": Error when closing file ID "+fileID+": "+e.getMessage());
        }
    }
}
项目:incubator-netbeans    文件:DockerInstanceChildFactory.java   
@Override
public void close() {
    Set<Node> nodes;
    synchronized (current) {
        nodes = new HashSet<>(current);
    }
    for (Node n : nodes) {
        for (Closeable c : n.getLookup().lookupAll(Closeable.class)) {
            try {
                c.close();
            } catch (IOException ex) {
                LOGGER.log(Level.INFO, null, ex);
            }
        }
    }
}
项目:elasticsearch_my    文件:IndicesService.java   
/**
 * This method verifies that the given {@code metaData} holds sane values to create an {@link IndexService}.
 * This method tries to update the meta data of the created {@link IndexService} if the given {@code metaDataUpdate} is different from the given {@code metaData}.
 * This method will throw an exception if the creation or the update fails.
 * The created {@link IndexService} will not be registered and will be closed immediately.
 */
public synchronized void verifyIndexMetadata(IndexMetaData metaData, IndexMetaData metaDataUpdate) throws IOException {
    final List<Closeable> closeables = new ArrayList<>();
    try {
        IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() {});
        closeables.add(indicesFieldDataCache);
        IndicesQueryCache indicesQueryCache = new IndicesQueryCache(settings);
        closeables.add(indicesQueryCache);
        // this will also fail if some plugin fails etc. which is nice since we can verify that early
        final IndexService service =
            createIndexService("metadata verification", metaData, indicesQueryCache, indicesFieldDataCache, emptyList(), s -> {});
        closeables.add(() -> service.close("metadata verification", false));
        service.mapperService().merge(metaData, MapperService.MergeReason.MAPPING_RECOVERY, true);
        if (metaData.equals(metaDataUpdate) == false) {
            service.updateMetaData(metaDataUpdate);
        }
    } finally {
        IOUtils.close(closeables);
    }
}
项目:AndroidDevSamples    文件:IOUtil.java   
/**
 * Close closable object and wrap {@link IOException} with {@link RuntimeException}
 * @param closeable closeable object
 */
public static void close(Closeable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (IOException e) {
            throw new RuntimeException("IOException occurred. ", e);
        }
    }
}
项目:ObjectCache    文件:Util.java   
static void closeQuietly(/*Auto*/Closeable closeable) {
  if (closeable != null) {
    try {
      closeable.close();
    } catch (RuntimeException rethrown) {
      throw rethrown;
    } catch (Exception ignored) {
    }
  }
}
项目:waggle-dance    文件:TSetIpAddressProcessorFactoryTest.java   
@Test
public void connectionIsMonitored() throws Exception {
  factory.getProcessor(transport);

  ArgumentCaptor<TTransport> transportCaptor = ArgumentCaptor.forClass(TTransport.class);
  ArgumentCaptor<Closeable> handlerCaptor = ArgumentCaptor.forClass(Closeable.class);
  verify(transportMonitor).monitor(transportCaptor.capture(), handlerCaptor.capture());
  assertThat(transportCaptor.getValue(), is(transport));
  assertThat(handlerCaptor.getValue(), is(instanceOf(FederatedHMSHandler.class)));
}
项目:atlas    文件:IOUtil.java   
public static void quietClose(Closeable closeable){
    if (closeable != null) {
        try {
            closeable.close();
        } catch (Throwable e) {
        }
    }
}
项目:Nird2    文件:DevReportServer.java   
private void tryToClose(@Nullable Closeable c) {
    try {
        if (c != null) c.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:encrypt    文件:CloseUtils.java   
public static void close(Closeable closeable) {
    if (null == closeable) return;
    try {
        closeable.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:Reer    文件:DefaultVersionedPlayRunAdapter.java   
private ClassLoader storeClassLoader(ClassLoader classLoader) {
    final ClassLoader previous = currentClassloader.getAndSet(classLoader);
    if (previous != null && previous instanceof Closeable) {
        loadersToClose.add(new SoftReference<Closeable>(Cast.cast(Closeable.class, previous)));
    }
    return classLoader;
}
项目:Exoplayer2Radio    文件:Util.java   
/**
 * Closes a {@link Closeable}, suppressing any {@link IOException} that may occur. Both {@link
 * java.io.OutputStream} and {@link InputStream} are {@code Closeable}.
 *
 * @param closeable The {@link Closeable} to close.
 */
public static void closeQuietly(Closeable closeable) {
  try {
    if (closeable != null) {
      closeable.close();
    }
  } catch (IOException e) {
    // Ignore.
  }
}
项目:hashsdn-controller    文件:RuntimeRegistratorFtlTemplate.java   
private RuntimeRegistratorFtlTemplate(RuntimeBeanEntry runtimeBeanEntry,
        String name, List<Field> fields, List<MethodDefinition> methods) {
    // TODO header
    super(null, runtimeBeanEntry.getPackageName(), name, Collections
            .emptyList(), Collections.singletonList(Closeable.class
            .getCanonicalName()), fields, methods);
}
项目:hadoop    文件:ConfiguredFailoverProxyProvider.java   
/**
 * Close all the proxy objects which have been opened over the lifetime of
 * this proxy provider.
 */
@Override
public synchronized void close() throws IOException {
  for (AddressRpcProxyPair<T> proxy : proxies) {
    if (proxy.namenode != null) {
      if (proxy.namenode instanceof Closeable) {
        ((Closeable)proxy.namenode).close();
      } else {
        RPC.stopProxy(proxy.namenode);
      }
    }
  }
}
项目:Coder    文件:DiskUtil.java   
static void closeQuietly(/*Auto*/Closeable closeable) {
  if (closeable != null) {
    try {
      closeable.close();
    } catch (RuntimeException rethrown) {
      throw rethrown;
    } catch (Exception ignored) {
    }
  }
}
项目:microhttpd    文件:CloseUtils.java   
public static void close(Closeable... closeables) {
    if (closeables != null) {
        for (Closeable it : closeables) {
            if (it != null) {
                try {
                    it.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
项目:CustomWorldGen    文件:PngSizeInfo.java   
public static PngSizeInfo makeFromResource(IResource resource) throws IOException
{
    PngSizeInfo pngsizeinfo;

    try
    {
        pngsizeinfo = new PngSizeInfo(resource.getInputStream());
    }
    finally
    {
        IOUtils.closeQuietly((Closeable)resource);
    }

    return pngsizeinfo;
}
项目:GitHub    文件:CropUtil.java   
public static void closeSilently(@Nullable Closeable c) {
    if (c == null) return;
    try {
        c.close();
    } catch (Throwable t) {
        // Do nothing
    }
}
项目:GitHub    文件:SharePatchFileUtil.java   
/**
 * Closes the given {@code Closeable}. Suppresses any IO exceptions.
 */
public static void closeQuietly(Closeable closeable) {
    try {
        if (closeable != null) {
            closeable.close();
        }
    } catch (IOException e) {
        Log.w(TAG, "Failed to close resource", e);
    }
}
项目:SuperSelector    文件:CropUtil.java   
public static void closeSilently(@Nullable Closeable c) {
    if (c == null) return;
    try {
        c.close();
    } catch (Throwable t) {
        // Do nothing
    }
}
项目:boohee_v5.6    文件:BitmapLoadUtils.java   
public static void close(@Nullable Closeable c) {
    if (c != null && (c instanceof Closeable)) {
        try {
            c.close();
        } catch (IOException e) {
        }
    }
}
项目:GitHub    文件:UpdateUtil.java   
public static void close(Closeable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
项目:pcloud-sdk-java    文件:IOUtils.java   
public static void closeQuietly(Closeable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
        }
    }
}
项目:uavstack    文件:CompressHelper.java   
/**
 * Close the stream which implements Closeable interface
 * 
 * @param stream
 */
private static void closeStream(Closeable stream) {

    if (null != stream) {
        try {
            stream.close();
        }
        catch (IOException e) {
            stream = null;
            e.printStackTrace();
        }
    }
}
项目:FirefoxData-android    文件:FutureRequestExecutionService.java   
public void close() throws IOException {
    closed.set(true);
    executorService.shutdownNow();
    if (httpclient instanceof Closeable) {
        ((Closeable) httpclient).close();
    }
}
项目:GitHub    文件:IOUtil.java   
public static void closeQuietly(Closeable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (Throwable ignored) {
            LogUtil.d(ignored.getMessage(), ignored);
        }
    }
}
项目:FlickLauncher    文件:Utils.java   
public static void closeSilently(Closeable c) {
    if (c == null) return;
    try {
        c.close();
    } catch (IOException t) {
        Log.w(TAG, "close fail ", t);
    }
}
项目:springreplugin    文件:CloseableUtils.java   
/**
 * 允许“一口气”关闭多个Closeable的方法
 *
 * @param closeables 多个Closeable对象
 */
public static void closeQuietly(final Closeable... closeables) {
    if (closeables == null) {
        return;
    }
    for (final Closeable closeable : closeables) {
        closeQuietly(closeable);
    }
}
项目:cloudterm    文件:IOHelper.java   
public static void close(Closeable... closables) {
    for (Closeable closable : closables) {
        try {
            closable.close();
        } catch (Exception e) {

        }
    }
}
项目:xlight_android_native    文件:EZ.java   
/**
 * For when you don't care if the Closeable you're closing is null, and
 * you don't care that closing a buffer threw an exception, but
 * you still care enough that logging might be useful, like in a
 * "finally" block, after you've already returned to the caller.
 */
public static void closeThisThingOrMaybeDont(@Nullable Closeable closeable) {
    if (closeable == null) {
        log.d("Can't close closable, arg was null.");
        return;
    }

    try {
        closeable.close();
    } catch (IOException e) {
        log.d("Couldn't close closable, but that's apparently OK.  Error was: " + e.getMessage());
    }
}
项目:fc-java-sdk    文件:XmlUtils.java   
private static void closeStream(Closeable stream) {
    if (stream != null) {
        try {
            stream.close();
        } catch (IOException e) {
        }
    }
}
项目:EazyBaseMVP    文件:IOUtils.java   
/**
 * Close closable object and wrap {@link IOException} with {@link RuntimeException}
 * @param closeable closeable object
 */
public static void close(Closeable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (IOException e) {
            throw new RuntimeException("IOException occurred. ", e);
        }
    }
}
项目:OpenJSharp    文件:URLClassLoader.java   
/**
* Closes this URLClassLoader, so that it can no longer be used to load
* new classes or resources that are defined by this loader.
* Classes and resources defined by any of this loader's parents in the
* delegation hierarchy are still accessible. Also, any classes or resources
* that are already loaded, are still accessible.
* <p>
* In the case of jar: and file: URLs, it also closes any files
* that were opened by it. If another thread is loading a
* class when the {@code close} method is invoked, then the result of
* that load is undefined.
* <p>
* The method makes a best effort attempt to close all opened files,
* by catching {@link IOException}s internally. Unchecked exceptions
* and errors are not caught. Calling close on an already closed
* loader has no effect.
* <p>
* @exception IOException if closing any file opened by this class loader
* resulted in an IOException. Any such exceptions are caught internally.
* If only one is caught, then it is re-thrown. If more than one exception
* is caught, then the second and following exceptions are added
* as suppressed exceptions of the first one caught, which is then re-thrown.
*
* @exception SecurityException if a security manager is set, and it denies
*   {@link RuntimePermission}{@code ("closeClassLoader")}
*
* @since 1.7
*/
public void close() throws IOException {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkPermission(new RuntimePermission("closeClassLoader"));
    }
    List<IOException> errors = ucp.closeLoaders();

    // now close any remaining streams.

    synchronized (closeables) {
        Set<Closeable> keys = closeables.keySet();
        for (Closeable c : keys) {
            try {
                c.close();
            } catch (IOException ioex) {
                errors.add(ioex);
            }
        }
        closeables.clear();
    }

    if (errors.isEmpty()) {
        return;
    }

    IOException firstex = errors.remove(0);

    // Suppress any remaining exceptions

    for (IOException error: errors) {
        firstex.addSuppressed(error);
    }
    throw firstex;
}
项目:letv    文件:jn.java   
public static void a(Closeable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (Throwable th) {
        }
    }
}
项目:BBSSDK-for-Android    文件:CloseUtils.java   
/**
 * 关闭IO
 *
 * @param closeables closeables
 */
public static void closeIO(final Closeable... closeables) {
    if (closeables == null) {
        return;
    }
    for (Closeable closeable : closeables) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}