本文整理汇总了Java中java.io.IOException.getSuppressed方法的典型用法代码示例。如果您正苦于以下问题:Java IOException.getSuppressed方法的具体用法?Java IOException.getSuppressed怎么用?Java IOException.getSuppressed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.IOException
的用法示例。
在下文中一共展示了IOException.getSuppressed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConnectionIOException_multiple
import java.io.IOException; //导入方法依赖的package包/类
@Test public void getConnectionIOException_multiple() {
IOException firstException = new IOException();
IOException secondException = new IOException();
IOException thirdException = new IOException();
RouteException re = new RouteException(firstException);
re.addConnectException(secondException);
re.addConnectException(thirdException);
IOException connectionIOException = re.getLastConnectException();
assertSame(thirdException, connectionIOException);
Throwable[] thirdSuppressedExceptions = thirdException.getSuppressed();
assertSame(secondException, thirdSuppressedExceptions[0]);
Throwable[] secondSuppressedException = secondException.getSuppressed();
assertSame(firstException, secondSuppressedException[0]);
}
示例2: close
import java.io.IOException; //导入方法依赖的package包/类
/**
* Closes all currently open files.
* Calling this method will not prevent the factory to open new files, i.e. this method can be called multiple times and is not idempotent.
*
* @throws IOException
*/
@Override
public synchronized void close() throws IOException {
IOException exception = new IOException("At least one open file could not be closed.");
for (Iterator<Map.Entry<Long, OpenFile>> it = openFiles.entrySet().iterator(); it.hasNext();) {
Map.Entry<Long, OpenFile> entry = it.next();
OpenFile openFile = entry.getValue();
LOG.warn("Closing unclosed file {}", openFile);
try {
openFile.close();
} catch (IOException e) {
exception.addSuppressed(e);
}
it.remove();
}
if (exception.getSuppressed().length > 0) {
throw exception;
}
}
示例3: checkException
import java.io.IOException; //导入方法依赖的package包/类
static void checkException(IOException e, TestCloseable... closeablesWithException) {
assertEquals(closeablesWithException[0].closeException, e);
Throwable[] suppressed = e.getSuppressed();
assertEquals(closeablesWithException.length - 1, suppressed.length);
for (int i = 1; i < closeablesWithException.length; i++)
assertEquals(closeablesWithException[i].closeException, suppressed[i - 1]);
}