Example usage for java.io Closeable close

List of usage examples for java.io Closeable close

Introduction

In this page you can find the example usage for java.io Closeable close.

Prototype

public void close() throws IOException;

Source Link

Document

Closes this stream and releases any system resources associated with it.

Usage

From source file:hosts.file.localvpn.LocalVPNService.java

private static void closeResources(Closeable... resources) {
    for (Closeable resource : resources) {
        if (resource == null)
            continue;
        try {/* w ww.j  ava 2  s.  c om*/
            resource.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.vizury.PushNotification.Engine.Sender.java

private static void close(Closeable closeable) {
    if (closeable != null) {
        try {/* w w w.j av a2s.  c  o m*/
            closeable.close();
        } catch (IOException e) {
            // ignore error
            logger.error("IOException closing stream" + e.getMessage());
        }
    }
}

From source file:Main.java

/**
 * Unconditionally close a <code>Closeable</code>.
 * <p/>//from w  w w . j  ava2s .  c  o m
 * 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 2.0
 */
public static void closeQuietly(Closeable closeable) {
    try {
        if (closeable != null) {
            closeable.close();
        }
    } catch (IOException ioe) {
        // ignore
    }
}

From source file:org.ensembl.healthcheck.util.InputOutputUtils.java

public static void close(Closeable closeable) {
    if (null != closeable) {
        try {//from   ww  w.  j ava2 s  .  com
            closeable.close();
        } catch (IOException e) {
            // don't log error
        }
    }
}

From source file:Main.java

public static void close(Closeable closeable) {
    if (closeable == null) {
        return;// w ww  . java 2s.c  o  m
    }

    if (closeable instanceof OutputStream) {
        try {
            ((OutputStream) closeable).flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    try {
        closeable.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.ignite.GridTestIoUtils.java

/**
 * Closes resource./*from w  w w . j av  a2s  .com*/
 *
 * @param c Resource
 * @throws IOException If failed to close resource.
 */
private static void close(Closeable c) throws IOException {
    if (c != null)
        c.close();
}

From source file:foam.zizim.android.net.BoskoiHttpClient.java

/**
 * Closes the specified stream./*from   www .j  ava  2s. c  o  m*/
 *
 * @param stream The stream to close.
 */
private static void closeStream(Closeable stream) {
    if (stream != null) {
        try {
            stream.close();
        } catch (IOException e) {
            //android.util.Log.e("IO", "Could not close stream", e);
        }
    }
}

From source file:io.milton.common.FileUtils.java

public static void close(Closeable in) {
    try {//from w  w w . j a  va  2s  .  co  m
        if (in == null) {
            return;
        }
        in.close();
    } catch (IOException ex) {
    }
}

From source file:com.ery.ertc.estorm.util.IOUtils.java

/**
 * Close the Closeable objects and <b>ignore</b> any {@link IOException} or
 * null pointers. Must only be used for cleanup in exception handlers.
 * /*from w ww .jav  a  2s.  c  o  m*/
 * @param log
 *            the log to record problems to at debug level. Can be null.
 * @param closeables
 *            the objects to close
 */
public static void cleanup(Log log, java.io.Closeable... closeables) {
    for (java.io.Closeable c : closeables) {
        if (c != null) {
            try {
                c.close();
            } catch (IOException e) {
                if (log != null && log.isDebugEnabled()) {
                    log.debug("Exception in closing " + c, e);
                }
            }
        }
    }
}

From source file:com.uphyca.kitkat.storage.internal.impl.LiveSdkSkyDriveClient.java

private static void closeQuietly(Closeable res) {
    if (res == null) {
        return;//from  w  ww .  j a  v  a2  s  .  c o m
    }
    try {
        res.close();
    } catch (IOException e) {
    }
}