From 180998e5ca18ac29490aa9103c32c672e9bd6bdb Mon Sep 17 00:00:00 2001 From: riking Date: Tue, 3 Jun 2014 17:46:52 -0700 Subject: [PATCH] Refactor: tryClose() method --- .../libraryaddict/disguise/LibsDisguises.java | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index dad9c1e6..90137f10 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -68,20 +68,8 @@ public class LibsDisguises extends JavaPlugin { } catch (IOException e) { e.printStackTrace(); } finally { - try { - if (stream != null) { - stream.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - try { - if (reader != null) { - reader.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } + tryClose(stream); + tryClose(reader); } PacketsManager.init(this); @@ -149,22 +137,20 @@ public class LibsDisguises extends JavaPlugin { } catch (Exception ex) { ex.printStackTrace(); } finally { + tryClose(input); + tryClose(reader); + } + return toWrite; + } + + private static void tryClose(Closeable input) { + if (input != null) { try { - if (input != null) { - input.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - try { - if (reader != null) { - reader.close(); - } + input.close(); } catch (IOException e) { e.printStackTrace(); } } - return toWrite; } /**