本文整理匯總了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]);
}