From 8213b41bc3b167c2b56046c58df42c0d76725c61 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 16 Nov 2015 00:36:46 +0100 Subject: [PATCH] Added closeQuietly methods --- Dorkbox-Util/src/dorkbox/util/Sys.java | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Dorkbox-Util/src/dorkbox/util/Sys.java b/Dorkbox-Util/src/dorkbox/util/Sys.java index 74dd8e3..090696a 100644 --- a/Dorkbox-Util/src/dorkbox/util/Sys.java +++ b/Dorkbox-Util/src/dorkbox/util/Sys.java @@ -175,6 +175,20 @@ class Sys { } } + /** + * Convenient close for a stream. + */ + @SuppressWarnings("Duplicates") + public static + void closeQuietly(InputStream inputStream) { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException ignored) { + } + } + } + /** * Convenient close for a stream. */ @@ -191,6 +205,20 @@ class Sys { } } + /** + * Convenient close for a stream. + */ + @SuppressWarnings("Duplicates") + public static + void closeQuietly(OutputStream outputStream) { + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException ignored) { + } + } + } + /** * Convenient close for a Reader. */ @@ -207,6 +235,20 @@ class Sys { } } + /** + * Convenient close for a Reader. + */ + @SuppressWarnings("Duplicates") + public static + void closeQuietly(Reader inputReader) { + if (inputReader != null) { + try { + inputReader.close(); + } catch (IOException ignored) { + } + } + } + /** * Convenient close for a Writer. */ @@ -223,6 +265,20 @@ class Sys { } } + /** + * Convenient close for a Writer. + */ + @SuppressWarnings("Duplicates") + public static + void closeQuietly(Writer outputWriter) { + if (outputWriter != null) { + try { + outputWriter.close(); + } catch (IOException ignored) { + } + } + } + /** * Copy the contents of the input stream to the output stream. *