Safely close some resource without throwing an exception.  Any exception will be logged at TRACE level.

@param c the resource
494605
public static void safeClose(final Closeable c) {
        if (c != null) {
            try {
                c.close();
            } catch (Exception e) {
                VFSLogger.ROOT_LOGGER.trace("Failed to close resource", e);
            }
        }
    }
333773
void _close()
                    throws SIResourceException, SIConnectionLostException,
                    SIErrorException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "_close");

        try
        {
            //close the LCP
            _localConsumerPoint.close();
        } catch (SINotPossibleInCurrentConfigurationException e)
        {
            // No FFDC code needed

            //Do nothing ... probably means that the Destination is being deleted
            //and so the LCP will be closed anyway
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                SibTr.debug(tc, "_close", e);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "_close");
    }
186434
public static void safeClose(@Nullable Closeable closeable) {
        if (closeable == null) return;

        try {
            closeable.close();
        } catch (IOException ignored) {
            // We made out best effort to release this resource. Nothing more we can do.
        }
    }
1133075
public static void safeClose(final Iterable<? extends Closeable> ci) {
        if (ci != null) {
            for (Closeable closeable : ci) {
                safeClose(closeable);
            }
        }
    }
1205908
void close() {

        try {
            clearLock();
            m_context.finish(Collections.singletonList(m_resource.getStructureId()));
        } catch (CmsException e) {
            m_context.error(e);
        }
    }
364061
public static boolean tryToClose(Closeable c) {
        if (c != null) {
            try {
                c.close();
                return true;
            } catch (IOException e) {
            }
        }
        return false;
    }
1240001
public static void close(@CheckForNull AutoCloseable c) {
        if (c == null) {
            return;
        }

        try {
            c.close();
        } catch (Exception e) {
            // Ignore
        }
    }
1314486
@Override
  public void close() throws IOException {
    shuttingDown = true;
    IOUtils.cleanup(null, executor);
    closeNamenodeRPC();
  }
98213
public static void close(FileDescriptor fd) throws IOException {
        try {
            if (fd != null && fd.valid()) {
                Libcore.os.close(fd);
            }
        } catch (ErrnoException errnoException) {
            throw errnoException.rethrowAsIOException();
        }
    }
421075
public static void safeClose(Closeable obj)
   {
      try
      {
         obj.close();
      }
      catch (IOException e)
      {
         LOG.error("Error while closing " + obj, e);
      }
   }
613918
@Override
	public void close() throws IOException {
		try {
			if (session != null) {
				session.close();
			}
		} catch (Exception e) {
			LOG.error("Error while closing session.", e);
		}

		try {
			if (cluster != null) {
				cluster.close();
			}
		} catch (Exception e) {
			LOG.error("Error while closing cluster.", e);
		}
	}
867723
public void destroy() {
        try {
            ctx.close();
        }
        catch (javax.naming.NamingException e) {
            LOG.warn("Error when closing", e);
        }
    }
77735
@Override
  public void close() throws IOException {
    try {
      mLock.lock();
      if (mAvailableResources.size() != mResources.size()) {
        LOG.warn("{} resources are not released when closing the resource pool.",
            mResources.size() - mAvailableResources.size());
      }
      for (ResourceInternal<T> resourceInternal : mAvailableResources) {
        closeResource(resourceInternal.mResource);
      }
      mAvailableResources.clear();
    } finally {
      mLock.unlock();
    }
    mGcFuture.cancel(true);
  }
1030697
public static void closeConnection(Connection connection)
        throws InternalErrorException {

        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                throw new InternalErrorException(e);
            }
        }

    }
148340
@Override
	public void close() {
		try {
			connection.close();
		} catch(IOException e) {
			log.log(Level.WARNING, "Could not close connection", e);
		}
	}
247864
@Override
    public void close(VirtualConnection inVC, Exception e) {
        final boolean bTrace = TraceComponent.isAnyTracingEnabled();
        if (bTrace && tc.isDebugEnabled()) {
            Tr.debug(tc, "close() called: " + this + " " + inVC);
        }

        boolean errorState = (null != e);
        if (errorState && bTrace && tc.isDebugEnabled()) {
            Tr.debug(tc, "close() in error state, " + e);
        }

        final HttpInboundServiceContextImpl sc = getHTTPContext();
        final HttpChannelConfig config = sc.getHttpConfig();
        // valid responses as well as error responses all go through here so
        // this is where we tell the factory that any large response is complete
        if (sc.containsLargeMessage()) {
            getChannel().getFactory().releaseLargeMessage();
        }

        // check to see if the message has been fully sent (unless we
        // are in an error state)

        if (!errorState && !sc.isMessageSent()) {
            try {
                VirtualConnection rc = sc.finishResponseMessage(null, this, false);
                // if the finish is done already, then continue with code below
                if (null == rc) {
                    if (bTrace && tc.isDebugEnabled()) {
                        Tr.debug(tc, "finishing response msg async");
                    }
                    return;
                }
            } catch (MessageSentException mse) {
                // no FFDC required, nothing to do here
                if (bTrace && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Error: message sent exception when flag doesn't agree");
                }
                // shouldn't get here so just close the socket
                getDeviceLink().close(inVC, mse);
                return;
            }
        }

        // if the incoming request body was never read, we must purge the body
        // off the socket before we can continue with the read for the next
        // request... assuming we're not in an error condition

        if (!errorState
            // 346196.2 -- if we stopped, then don't purge the body
            && getChannel().isRunning() && !sc.isIncomingMessageFullyRead()) {
            if (bTrace && tc.isDebugEnabled()) {
                Tr.debug(tc, "Incoming request body never read.");
            }
            try {
                // 346196.4 - read/release one buffer at a time to avoid
                // unnecessary memory storage for large bodies
                VirtualConnection rc = sc.getRequestBodyBuffer(HttpIgnoreBodyCallback.getRef(), false);
                boolean reachedEnd = false;
                while (null != rc) {
                    WsByteBuffer buffer = sc.getRequestBodyBuffer();
                    if (null != buffer) {
                        buffer.release();
                        rc = sc.getRequestBodyBuffer(HttpIgnoreBodyCallback.getRef(), false);
                    } else {
                        // end of body found
                        reachedEnd = true;
                        break;
                    }
                }
                if (!reachedEnd) {
                    // wait for callback
                    if (bTrace && tc.isDebugEnabled()) {
                        Tr.debug(tc, "close() waiting for body purge callback");
                    }
                    return;
                }
            } catch (Exception purgeException) {
                // no FFDC required
                if (bTrace && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Exception purging request body: " + purgeException);
                }
                errorState = true;
            }
        }

        if (this.myInterface.getLink() instanceof H2HttpInboundLinkWrap) {
            if (bTrace && tc.isDebugEnabled()) {
                Tr.debug(tc, "we're H2, calling that close");
            }
            this.myInterface.getLink().close(inVC, e);

            return;
        }

        // If servlet upgrade processing is being used, then don't close the socket here
        if (inVC != null) {
            String upgraded = (String) (inVC.getStateMap().get(TransportConstants.UPGRADED_CONNECTION));
            if (upgraded != null) {
                if (!errorState && getChannel().isRunning() && (upgraded.compareToIgnoreCase("true") == 0)) {

                    if (bTrace && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Connection Not closed because Servlet Upgrade detected.");
                    }
                    return;
                }
            }
        }

        // now check to see if the connection should be kept open (unless
        // we are in an error state). Perform one last check against a channel
        // stop, close the socket if not running.

        if (!errorState && sc.isPersistent() && getChannel().isRunning()) {

            if (config.getDebugLog().isEnabled(DebugLog.Level.DEBUG)) {
                config.getDebugLog().log(DebugLog.Level.DEBUG, HttpMessages.MSG_READ_PERSISTENT, sc);
            }

            sc.resetStartTime();
            this.myTSC.getWriteInterface().setBuffers(null);

            // check the last buffer from the previous request as
            // there might be the start of another request on it (pipelining)

            if (sc.isReadDataAvailable()) {
                handlePipeLining();
                return;
            }
            // no pipelined data, clear the SC and setup for a JIT read
            if (bTrace && tc.isDebugEnabled()) {
                Tr.debug(tc, "Reading for another request...");
            }
            if (getChannel().getHttpConfig().runningOnZOS()) {
                // 342859 - add a marker indicating the first read of a subsequent
                // request is starting. This is used for WLM type management on z/OS
                // right now with request message priority handling and monitoring
                // of "in-system" times
                getVirtualConnection().getStateMap().put(HttpConstants.HTTPFirstRead, "true");
            }

            sc.clear();
            sc.setReadBuffer(null);
            sc.setupJITRead(config.getIncomingHdrBufferSize());

            // do a forced async read to free up the thread since there will
            // no doubt be a delay until the next request -- we've already
            // checked for pipelined ones
            this.myTSC.getReadInterface().read(1, HttpICLReadCallback.getRef(), true, config.getPersistTimeout());

        } else {
            if (bTrace && tc.isDebugEnabled()) {
                Tr.debug(tc, "Closing connection");
            }

            //PI11176 Begin
            if (getChannel().getHttpConfig().shouldAttemptPurgeData()) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "attemptPurgeData true, purging the data before closing the connection");
                }
                try {
                    //Setup for a JIT read. This will allocate a buffer for X bytes if a buffer hasn't already been allocated
                    //If there is nothing to read the buffer is automatically released
                    sc.setupJITRead(10);
                    //Set the buffer to null at the TCP layer before continuing. We will be doing this after anyway, so want to do it ahead of time so we are starting with out buffer.
                    this.myTSC.getReadInterface().setBuffer(null);
                    boolean processing = true;

                    while (processing) {
                        //Do the read
                        long numBytesRead = this.myTSC.getReadInterface().read(0, 1);
                        //Get the buffer associated with the read, could return null
                        WsByteBuffer indivBuffer = this.myTSC.getReadInterface().getBuffer();
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "Bytes read : " + numBytesRead);
                        }
                        //Check if the bytesRead are 0. If so then we are done. If not then we have to process the data(which in this case means throw it out
                        if (numBytesRead <= 0) {
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(tc, "No data read");
                            }
                            if (indivBuffer != null) {
                                //Means we read more than once to set the buffer to null and release it
                                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                    Tr.debug(tc, "No data read, releasing any buffer that was allocated");
                                }
                                this.myTSC.getReadInterface().setBuffer(null);
                                indivBuffer.release();
                            }
                            processing = false;
                        } else {
                            if (indivBuffer != null) {
                                //Clear the buffer because we read some data
                                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                    Tr.debug(tc, "Found a buffer after the read : " + indivBuffer);
                                }
                                indivBuffer.clear();
                                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                    Tr.debug(tc, "Cleared the buffer, going back to read again, " + indivBuffer);
                                }
                            } else {
                                //We are done since there was no buffer
                                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                    Tr.debug(tc, "No buffer found, assuming we are done");
                                }
                                processing = false;
                            }

                        }
                    }
                } catch (IOException purgeException) {
                    //Encountered an exception, if there is a buffer, just release and null out
                    WsByteBuffer indivBuffer = this.myTSC.getReadInterface().getBuffer();
                    if (indivBuffer != null) {
                        this.myTSC.getReadInterface().setBuffer(null);
                        indivBuffer.release();
                    }
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "IOException during purge : " + purgeException);
                    }
                }
            }
            //PI11176 End

            if (config.getDebugLog().isEnabled(DebugLog.Level.INFO)) {
                config.getDebugLog().log(DebugLog.Level.INFO, HttpMessages.MSG_CONN_CLOSING, sc);
            }

            if (this.myTSC != null) {
                TCPWriteRequestContext writeInterface = this.myTSC.getWriteInterface();
                if (writeInterface != null)
                    writeInterface.setBuffer(null);
                TCPReadRequestContext readInterface = this.myTSC.getReadInterface();
                if (readInterface != null)
                    readInterface.setBuffer(null);
            }
            if (this.filterExceptions) {
                getDeviceLink().close(inVC, null);
            } else {
                getDeviceLink().close(inVC, e);
            }
        }
    }
387062
@Override
    public void close(VirtualConnection inVC, Exception e) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "close(vc, e) called H2InboundLink: " + this + " " + inVC);
        }

        //At this point our side should be in the close state, as we have sent out our data
        //Should probably check if the connection is closed, if so issue the destroy up the chain
        //Then call the close on the underlying muxLink so we can close the connection if everything has been closed
        //Additionally, don't close the underlying link if this is a push stream
        if (streamID == 0 || streamID % 2 == 1) {
            // if this isn't an http/2 exception, don't pass it down, since that will cause a GOAWAY to be sent immediately
            if (e == null || e instanceof Http2Exception) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "close: closing with exception: " + e);
                }
                if (httpInboundServiceContextImpl != null) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "close: (1)httpInboundServiceContextImpl.clear()");
                    }
                    httpInboundServiceContextImpl.clear();
                    httpInboundServiceContextImpl = null;
                }
                this.muxLink.close(inVC, e);
            } else {
                H2StreamProcessor h2sp = muxLink.getStreamProcessor(streamID);
                if (h2sp != null && !h2sp.isStreamClosed()) {
                    try {
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "close: attempting to reset stream: " + streamID);
                        }
                        int PROTOCOL_ERROR = 0x1;
                        Frame reset = new FrameRstStream(streamID, PROTOCOL_ERROR, false);
                        h2sp.processNextFrame(reset, Constants.Direction.WRITING_OUT);
                    } catch (Http2Exception h2e) {
                        // if we can't write out RST frame, throw the original exception
                        if (httpInboundServiceContextImpl != null) {
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(tc, "close: (2)httpInboundServiceContextImpl.clear()");
                            }
                            httpInboundServiceContextImpl.clear();
                            httpInboundServiceContextImpl = null;
                        }
                        this.muxLink.close(inVC, e);
                    }
                }
                if (httpInboundServiceContextImpl != null) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "close: (3)httpInboundServiceContextImpl.clear()");
                    }
                    httpInboundServiceContextImpl.clear();
                    httpInboundServiceContextImpl = null;
                }
                this.muxLink.close(inVC, null);
            }
        } else { // try to send an RST_STREAM to let the client know the push promise has been canceled
            H2StreamProcessor h2sp = muxLink.getStreamProcessor(streamID);
            if (h2sp != null && !h2sp.isStreamClosed() && !h2sp.isHalfClosed()) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "close: attempting to reset stream: " + streamID);
                }
                int PROTOCOL_ERROR = 0x1;
                Frame reset = new FrameRstStream(streamID, PROTOCOL_ERROR, false);
                try {
                    h2sp.processNextFrame(reset, Constants.Direction.WRITING_OUT);
                } catch (Http2Exception h2e) {
                    // don't close
                }
            }
        }
    }