當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。