From 02dbf827112b4384b8220748b330940234fd902f Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 22 Aug 2014 13:51:02 +0200 Subject: [PATCH] Added aborting of the client registration process, if it fails during the registration process. Wrapped logger.debug/trace into checks first. Tweaked caller of RmiBridge --- Dorkbox-Util/src/dorkbox/util/FileUtil.java | 29 +++++++++++++++---- .../src/dorkbox/util/InputConsole.java | 19 ++++++++---- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Dorkbox-Util/src/dorkbox/util/FileUtil.java b/Dorkbox-Util/src/dorkbox/util/FileUtil.java index 53e15f4..f496c3a 100644 --- a/Dorkbox-Util/src/dorkbox/util/FileUtil.java +++ b/Dorkbox-Util/src/dorkbox/util/FileUtil.java @@ -126,7 +126,10 @@ public class FileUtil { parentOut.mkdirs(); } - logger.trace("Copying file: {} --> {}", in, out); + Logger logger2 = logger; + if (logger2.isTraceEnabled()) { + logger2.trace("Copying file: {} --> {}", in, out); + } FileChannel sourceChannel = null; FileChannel destinationChannel = null; @@ -221,7 +224,10 @@ public class FileUtil { // if directory not exists, create it if (!dest.exists()) { dest.mkdir(); - logger.trace("Directory copied from {} --> {}", src, dest); + Logger logger2 = logger; + if (logger2.isTraceEnabled()) { + logger2.trace("Directory copied from {} --> {}", src, dest); + } } // list all the directory contents @@ -266,7 +272,10 @@ public class FileUtil { // if directory not exists, create it if (!dest.exists()) { dest.mkdir(); - logger.trace("Directory copied from {} --> {}", src, dest); + Logger logger2 = logger; + if (logger2.isTraceEnabled()) { + logger2.trace("Directory copied from {} --> {}", src, dest); + } } // list all the directory contents @@ -301,18 +310,23 @@ public class FileUtil { * Deletes a file or directory and all files and sub-directories under it. */ public static boolean delete(File file) { + Logger logger2 = logger; if (file.exists() && file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0, n = files.length; i < n; i++) { if (files[i].isDirectory()) { delete(files[i].getAbsolutePath()); } else { - logger.trace("Deleting file: {}", files[i]); + if (logger2.isTraceEnabled()) { + logger2.trace("Deleting file: {}", files[i]); + } files[i].delete(); } } } - logger.trace("Deleting file: {}", file); + if (logger2.isTraceEnabled()) { + logger2.trace("Deleting file: {}", file); + } return file.delete(); } @@ -328,7 +342,10 @@ public class FileUtil { String path = location.getAbsolutePath(); if (location.mkdirs()) { - logger.trace("Created directory: {}", path); + Logger logger2 = logger; + if (logger2.isTraceEnabled()) { + logger2.trace("Created directory: {}", path); + } } return path; diff --git a/Dorkbox-Util/src/dorkbox/util/InputConsole.java b/Dorkbox-Util/src/dorkbox/util/InputConsole.java index c9c4e16..a3c3504 100644 --- a/Dorkbox-Util/src/dorkbox/util/InputConsole.java +++ b/Dorkbox-Util/src/dorkbox/util/InputConsole.java @@ -12,6 +12,7 @@ import jline.console.ConsoleReader; import org.fusesource.jansi.Ansi; import org.fusesource.jansi.AnsiConsole; +import org.slf4j.Logger; public class InputConsole { private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(InputConsole.class); @@ -96,10 +97,13 @@ public class InputConsole { terminal.setEchoEnabled(true); this.isIDE = terminal instanceof IDE_Terminal; - if (this.isIDE) { - logger.debug("Terminal is in IDE (best guess). Unable to support single key input. Only line input available."); - } else { - logger.debug("Terminal Type: {}", terminal.getClass().getSimpleName()); + Logger logger2 = logger; + if (logger2.isDebugEnabled()) { + if (this.isIDE) { + logger2.debug("Terminal is in IDE (best guess). Unable to support single key input. Only line input available."); + } else { + logger2.debug("Terminal Type: {}", terminal.getClass().getSimpleName()); + } } } catch (UnsupportedEncodingException ignored) { } catch (IOException ignored) { @@ -225,8 +229,9 @@ public class InputConsole { } private final void run() { + Logger logger2 = logger; if (this.jlineReader == null) { - logger.error("Unable to start Console Reader"); + logger2.error("Unable to start Console Reader"); return; } @@ -264,7 +269,9 @@ public class InputConsole { while ((typedChar = this.jlineReader.readCharacter()) != -1) { char asChar = (char) typedChar; - logger.trace("READ: {} ({})", asChar, typedChar); + if (logger2.isTraceEnabled()) { + logger2.trace("READ: {} ({})", asChar, typedChar); + } // notify everyone waiting for a character. synchronized (this.inputLockSingle) {