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


Java Closeable类代码示例

本文整理汇总了Java中java.io.Closeable的典型用法代码示例。如果您正苦于以下问题:Java Closeable类的具体用法?Java Closeable怎么用?Java Closeable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Closeable类属于java.io包,在下文中一共展示了Closeable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAppContextClassHierarchy

import java.io.Closeable; //导入依赖的package包/类
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));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:20,代码来源:ClassUtilsTest.java

示例2: destroy

import java.io.Closeable; //导入依赖的package包/类
@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();
}
 
开发者ID:vladmihalcea,项目名称:hibernate-types,代码行数:17,代码来源:AbstractTest.java

示例3: getSQLCommandsFromFile_closeStream_ioException

import java.io.Closeable; //导入依赖的package包/类
@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));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:DatabaseUpgradeHandlerTest.java

示例4: testCheckSchemaSupport2

import java.io.Closeable; //导入依赖的package包/类
/**
 * 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();
        }
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:DocumentBuilderFactoryTest.java

示例5: handleClose

import java.io.Closeable; //导入依赖的package包/类
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());
		}
	}
}
 
开发者ID:matthieu-labas,项目名称:JRF,代码行数:24,代码来源:JRFProvider.java

示例6: close

import java.io.Closeable; //导入依赖的package包/类
@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);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:DockerInstanceChildFactory.java

示例7: verifyIndexMetadata

import java.io.Closeable; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:IndicesService.java

示例8: close

import java.io.Closeable; //导入依赖的package包/类
/**
 * 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);
        }
    }
}
 
开发者ID:jiajieshen,项目名称:AndroidDevSamples,代码行数:14,代码来源:IOUtil.java

示例9: closeQuietly

import java.io.Closeable; //导入依赖的package包/类
static void closeQuietly(/*Auto*/Closeable closeable) {
  if (closeable != null) {
    try {
      closeable.close();
    } catch (RuntimeException rethrown) {
      throw rethrown;
    } catch (Exception ignored) {
    }
  }
}
 
开发者ID:myntra,项目名称:ObjectCache,代码行数:11,代码来源:Util.java

示例10: connectionIsMonitored

import java.io.Closeable; //导入依赖的package包/类
@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)));
}
 
开发者ID:HotelsDotCom,项目名称:waggle-dance,代码行数:11,代码来源:TSetIpAddressProcessorFactoryTest.java

示例11: quietClose

import java.io.Closeable; //导入依赖的package包/类
public static void quietClose(Closeable closeable){
    if (closeable != null) {
        try {
            closeable.close();
        } catch (Throwable e) {
        }
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:9,代码来源:IOUtil.java

示例12: tryToClose

import java.io.Closeable; //导入依赖的package包/类
private void tryToClose(@Nullable Closeable c) {
	try {
		if (c != null) c.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:8,代码来源:DevReportServer.java

示例13: close

import java.io.Closeable; //导入依赖的package包/类
public static void close(Closeable closeable) {
    if (null == closeable) return;
    try {
        closeable.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:GcsSloop,项目名称:encrypt,代码行数:9,代码来源:CloseUtils.java

示例14: storeClassLoader

import java.io.Closeable; //导入依赖的package包/类
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;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:8,代码来源:DefaultVersionedPlayRunAdapter.java

示例15: closeQuietly

import java.io.Closeable; //导入依赖的package包/类
/**
 * 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.
  }
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:16,代码来源:Util.java


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