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]); } }
public static void safeCopyFile(File child, File destChild) throws IOException { forceMkdirs(destChild.getParentFile()); IOException ioException = null; while (true) { try { FileUtils.copyFile(child, destChild); return; } catch (IOException e) { if (ioException == null) { ioException = e; } else { ioException.addSuppressed(e); } if (ioException.getSuppressed().length >= MAX_COPY_ATTEMPTS) { LOGGER.warn("Unable to copy {} to {} after " + MAX_COPY_ATTEMPTS + " attempts; skipping file", child, destChild, e); return; } } } } }
Throwable[] suppressed = e.getSuppressed(); if (GenericUtils.length(suppressed) > 0) { for (Throwable t : suppressed) {
@Override public void destroy() { // NOTE !!! DO NOT NULL-IFY THE PROCESS SINCE "exitValue" is called subsequently if (process != null) { log.debug("Destroy process for " + cmdValue); process.destroy(); } IOException e = IoUtils.closeQuietly(getInputStream(), getOutputStream(), getErrorStream()); if (e != null) { if (log.isDebugEnabled()) { log.debug(e.getClass().getSimpleName() + " while destroy streams of '" + this + "': " + e.getMessage()); } if (log.isTraceEnabled()) { Throwable[] suppressed = e.getSuppressed(); if (GenericUtils.length(suppressed) > 0) { for (Throwable t : suppressed) { log.trace("Suppressed " + t.getClass().getSimpleName() + ") while destroy streams of '" + this + "': " + t.getMessage()); } } } } }
Throwable[] suppressed = e.getSuppressed(); if (GenericUtils.length(suppressed) > 0) { for (Throwable t : suppressed) {
@Override public void destroy() { // NOTE !!! DO NOT NULL-IFY THE PROCESS SINCE "exitValue" is called subsequently if (process != null) { log.debug("Destroy process for " + cmdValue); process.destroy(); } IOException e = IoUtils.closeQuietly(getInputStream(), getOutputStream(), getErrorStream()); if (e != null) { if (log.isDebugEnabled()) { log.debug(e.getClass().getSimpleName() + " while destroy streams of '" + this + "': " + e.getMessage()); } if (log.isTraceEnabled()) { Throwable[] suppressed = e.getSuppressed(); if (GenericUtils.length(suppressed) > 0) { for (Throwable t : suppressed) { log.trace("Suppressed " + t.getClass().getSimpleName() + ") while destroy streams of '" + this + "': " + t.getMessage()); } } } } }
@Override protected void preClose() { if (!isEofSent()) { log.debug("close({}) prevent sending EOF", this); } try { signalChannelClosed(null); } finally { // clear the listeners since we are closing the channel (quicker GC) this.channelListeners.clear(); } IOException err = IoUtils.closeQuietly(getLocalWindow(), getRemoteWindow()); if (err != null) { if (log.isDebugEnabled()) { log.debug("Failed (" + err.getClass().getSimpleName() + ") to pre-close window(s) of " + this + ": " + err.getMessage()); } if (log.isTraceEnabled()) { Throwable[] suppressed = err.getSuppressed(); if (GenericUtils.length(suppressed) > 0) { for (Throwable t : suppressed) { log.trace("Suppressed " + t.getClass().getSimpleName() + ") while pre-close window(s) of " + this + ": " + t.getMessage()); } } } } super.preClose(); }
@Override protected void preClose() { if (!isEofSent()) { log.debug("close({}) prevent sending EOF", this); } try { signalChannelClosed(null); } finally { // clear the listeners since we are closing the channel (quicker GC) this.channelListeners.clear(); // clear the attributes since we close the channel clearAttributes(); } IOException err = IoUtils.closeQuietly(getLocalWindow(), getRemoteWindow()); if (err != null) { if (log.isDebugEnabled()) { log.debug("Failed (" + err.getClass().getSimpleName() + ") to pre-close window(s) of " + this + ": " + err.getMessage()); } if (log.isTraceEnabled()) { Throwable[] suppressed = err.getSuppressed(); if (GenericUtils.length(suppressed) > 0) { for (Throwable t : suppressed) { log.trace("Suppressed " + t.getClass().getSimpleName() + ") while pre-close window(s) of " + this + ": " + t.getMessage()); } } } } super.preClose(); }