/** * Helper method used when value to serialize is {@link Closeable} and its <code>close()</code> * method is to be called right after serialization has been called */ private final void _writeCloseable(JsonGenerator jgen, Object value, SerializationConfig cfg) throws IOException, JsonGenerationException, JsonMappingException { Closeable toClose = (Closeable) value; try { if (_rootType == null) { _serializerProvider(cfg).serializeValue(jgen, value); } else { _serializerProvider(cfg).serializeValue(jgen, value, _rootType, _rootSerializer); } JsonGenerator tmpJgen = jgen; jgen = null; tmpJgen.close(); Closeable tmpToClose = toClose; toClose = null; tmpToClose.close(); } finally { /* Need to close both generator and value, as long as they haven't yet * been closed */ if (jgen != null) { try { jgen.close(); } catch (IOException ioe) { } } if (toClose != null) { try { toClose.close(); } catch (IOException ioe) { } } } }
public void stop() { for (Closeable c : closeables) try { c.close(); } catch (IOException ignore) { } ChatHandler.removeAll(); }
/** * Close all {@link Closeable}s except for <i>n</i> of them. * * @param n The number of {@link Closeable}s to keep open at most. */ void closeAllBut(int n) throws IOException { synchronized (m_closeableList) { while (m_closeableList.size() > n) { final Closeable closeable = m_closeableList.removeFirst(); synchronized (closeable) { closeable.close(); } } } }
/** * Closes all not-null resources All possible IOExceptions are ignored * * @param toClose resources to close * @since 7.0 */ public static void closeAll(@NotNull Closeable... toClose) { for (Closeable e : toClose) { if (e != null) { try { e.close(); } catch (IOException e1) { // ignore } } } }
@Override public void close() throws IOException { out.close(); br.close(); ous.close(); ois.close(); socket.close(); for (Closeable extraCloseable : extraCloseables) { extraCloseable.close(); } }
private void safeClose(@Nullable Closeable enumerator, MavenIndexException[] exceptions) { try { if (enumerator != null) enumerator.close(); } catch (IOException e) { MavenLog.LOG.warn(e); if (exceptions[0] == null) exceptions[0] = new MavenIndexException(e); } }
private static final void safeClose(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (IOException e) { } } }
public static void closeResource(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (IOException ignored) { } } }
public static void closeQuietly(Closeable closeable) { try { if (closeable != null) { closeable.close(); } } catch (IOException e) { } }
/** * @param out The closeable (Writer, Stream, etc.) to close */ public static void close(final Closeable out) { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } }
/** * Unconditionally close a <code>Closeable</code>. * * <p>Equivalent to {@link Closeable#close()}, except any exceptions will be ignored. This is * typically used in finally blocks. * * <p>Example code: * * <pre> * Closeable closeable = null; * try { * closeable = new FileReader("foo.txt"); * // process closeable * closeable.close(); * } catch (Exception e) { * // error handling * } finally { * IOUtils.closeQuietly(closeable); * } * </pre> * * @param closeable the object to close, may be null or already closed * @since Commons IO 2.0 */ private static void closeQuietly(Closeable closeable) { try { if (closeable != null) { closeable.close(); } } catch (IOException ioe) { // ignore } }
public static void closeSilently(Closeable stream) { if (stream != null) { try { stream.close(); } catch (IOException e) { // close silently } } }
public void closeQuietly(Closeable s) { if (s != null) { try { s.close(); } catch (IOException e) { e.printStackTrace(); } } }
/** * Close stream or resource. * * @param closeable */ private void close(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (Exception e) { log.trace("Error closing stream or resource", e); } } }
/** * Closes a resource if it is not null All possible IOExceptions are ignored * * @param e resource to close */ public static void close(@Nullable Closeable e) { if (e != null) { try { e.close(); } catch (IOException e1) { // ignore } } }
public static void close(Closeable c) { if (c == null) { return; } try { c.close(); } catch (IOException e) { log.warn("Can't close file streams.", e); } }
public void close() { for (ClassDataCollector cd : delegates) try { if (cd instanceof Closeable) ((Closeable) cd).close(); } catch (Exception e) { reporter.error("Fail to call close on %s", cd); } delegates.clear(); shortlist.clear(); }
/** * Close the given resource. * * @param resource The resource to be closed. */ private static void close(Closeable resource) { if (resource != null) { try { resource.close(); } catch (IOException ignore) { // Ignore IOException. If you want to handle this anyway, it might be useful to know // that this will generally only be thrown when the client aborted the request. } } }
/** * Closes the given {@link Closeable} ignoring the I/O exception that might occur. Does nothing if * <code>null</code> is given as argument. */ public static void closeSilently(@CheckForNull Closeable closeable) { if (closeable == null) { return; } try { closeable.close(); } catch (IOException e) { // ignore } }
public static void close(Closeable c) { // convenience if (c != null) { try { c.close(); } catch (IOException e) { e.printStackTrace(); } } }
public static void closeQuietly(Closeable closeable, String streamDescription) { if (closeable != null) { try { closeable.close(); } catch (IOException ex) { if (!isEmpty(streamDescription)) { log.severe("error closing stream " + streamDescription + ": " + ex); } } } }
public static void closeQuietly(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (RuntimeException e) { throw e; } catch (Exception e) { e.printStackTrace(); } } }
@Override public void close() { for (Object it : cache.values()) { if (it instanceof Closeable) { try { ((Closeable) it).close(); } catch (IOException e) { error(e); } } } }
void closeQuietly(final Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (final IOException e) { e.printStackTrace(); } } }
protected boolean close(Closeable closeable) { if (closeable != null) { try { closeable.close(); return true; } catch (IOException e) { // mute } } return false; }
/** * Helper method used when value to serialize is {@link Closeable} and its <code>close()</code> * method is to be called right after serialization has been called */ private final void _writeCloseableValue(JsonGenerator jgen, Object value, SerializationConfig cfg) throws IOException, JsonGenerationException, JsonMappingException { Closeable toClose = (Closeable) value; try { if (_rootType == null) { _serializerProvider(cfg).serializeValue(jgen, value); } else { _serializerProvider(cfg).serializeValue(jgen, value, _rootType, _rootSerializer); } if (_config.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)) { jgen.flush(); } Closeable tmpToClose = toClose; toClose = null; tmpToClose.close(); } finally { if (toClose != null) { try { toClose.close(); } catch (IOException ioe) { } } } }
public static void close(final Closeable closeable) { if (closeable == null) return; try { if (Flushable.class.isInstance(closeable)) { ((Flushable) closeable).flush(); } } catch (Throwable e) { // Ignore } try { closeable.close(); } catch (Throwable e) { // Ignore } }
public void closePrinters() throws PrinterManagerException { PrinterManagerException printerManagerException = new PrinterManagerException(); for (Printer printer : printers) { if (printer instanceof Closeable) { try { ((Closeable) printer).close(); } catch (PrinterException e) { printerManagerException.addPrinterException(e); } } } if (!printerManagerException.getPrinterExceptions().isEmpty()) { throw printerManagerException; } }
/** * Writes the RTF document and send the output to an {@link Appendable}. This method closes the * {@link Appendable} after writing if its of type {@link Closeable}. * * @param out Destination of this RTF output. */ public void out(Appendable out) { if (out == null) throw new IllegalArgumentException("Appendable is not allowed to be null"); try { writeRtfDocument(out); } catch (IOException e) { throw new RtfException(e); } finally { if (out instanceof Closeable) try { ((Closeable) out).close(); } catch (IOException e) { throw new RtfException(e); } } }
/** * Method that will close an {@link java.io.Closeable} ignoring it if it is null and ignoring * exceptions. * * @param closeable the closeable to close. * @since jEdit 4.3pre8 */ public static void closeQuietly(Closeable closeable) { if (closeable != null) { try { if (closeable instanceof Flushable) { ((Flushable) closeable).flush(); } } catch (IOException e) { // ignore } try { closeable.close(); } catch (IOException e) { // ignore } } } // }}}