diff --git a/util/src/main/java/de/muehlencord/shared/util/OSUtil.java b/util/src/main/java/de/muehlencord/shared/util/OSUtil.java index e53422b..4b5f274 100644 --- a/util/src/main/java/de/muehlencord/shared/util/OSUtil.java +++ b/util/src/main/java/de/muehlencord/shared/util/OSUtil.java @@ -1,12 +1,7 @@ -/* - * OSUtil.java - * - * Created on 10. Dezember 2007, 16:50 - * - */ package de.muehlencord.shared.util; import static java.lang.System.getProperties; +import java.util.Locale; /** * @@ -31,7 +26,7 @@ public abstract class OSUtil { public static int getOperationSystem() { String osName = getProperties().getProperty("os.name"); if (osName != null) { - osName = osName.toUpperCase(); + osName = osName.toUpperCase(Locale.getDefault()); if (osName.contains("WINDOWS")) { return OS_WINDOWS; } else if (osName.contains("LINUX")) { diff --git a/util/src/main/java/de/muehlencord/shared/util/StringUtil.java b/util/src/main/java/de/muehlencord/shared/util/StringUtil.java index 67c374f..eab326a 100644 --- a/util/src/main/java/de/muehlencord/shared/util/StringUtil.java +++ b/util/src/main/java/de/muehlencord/shared/util/StringUtil.java @@ -1,14 +1,8 @@ -/* - * StringUtil.java - * - * Created on 4. Mai 2007, 12:36 - */ package de.muehlencord.shared.util; import java.io.UnsupportedEncodingException; import java.text.ParseException; import org.apache.log4j.Logger; -import static org.apache.log4j.Logger.getLogger; /** * @@ -17,7 +11,7 @@ import static org.apache.log4j.Logger.getLogger; public abstract class StringUtil { /** the logging object */ - private static final Logger logger = getLogger(StringUtil.class); + private static final Logger LOGGER = Logger.getLogger(StringUtil.class); /** * returns the given string in ISO-8859-1 encoding @@ -32,7 +26,7 @@ public abstract class StringUtil { byte[] b = input.getBytes("UTF-8"); return new String(b, "ISO-8859-1"); } catch (UnsupportedEncodingException ex) { - logger.debug(getStackTraceString(ex)); + LOGGER.debug(getStackTraceString(ex)); throw new StringEncodingException("Cannot convert string from UTF-8 to ISO-8859-1. Reason: " + ex.getMessage(), ex); } } @@ -44,12 +38,16 @@ public abstract class StringUtil { * @return the stackstrace as one string */ public static String getStackTraceString(Throwable ex) { - String logString = ex.toString() + "\n"; + StringBuilder sb = new StringBuilder(); + sb.append (ex.toString()); + sb.append ("\n"); + StackTraceElement[] stack = ex.getStackTrace(); - for (StackTraceElement stack1 : stack) { - logString += (stack1.toString()) + "\n"; + for (StackTraceElement currentElement : stack) { + sb.append (currentElement.toString()); + sb.append ("\n"); } - return logString; + return sb.toString(); } /** @@ -68,11 +66,12 @@ public abstract class StringUtil { return ""; } - String returnValue = s; - while (s.length() < length) { - returnValue += " "; + StringBuilder sb = new StringBuilder(); + sb.append (s); + while (sb.toString().length() < length) { + sb.append (" "); } - return returnValue; + return sb.toString(); } /** diff --git a/util/src/main/java/de/muehlencord/shared/util/file/FileUtil.java b/util/src/main/java/de/muehlencord/shared/util/file/FileUtil.java index 50d09a8..4e95311 100644 --- a/util/src/main/java/de/muehlencord/shared/util/file/FileUtil.java +++ b/util/src/main/java/de/muehlencord/shared/util/file/FileUtil.java @@ -17,7 +17,6 @@ import static java.util.Arrays.asList; import java.util.LinkedList; import java.util.List; import org.apache.log4j.Logger; -import static org.apache.log4j.Logger.getLogger; /** * @@ -28,7 +27,7 @@ public abstract class FileUtil { /** * the logging object */ - private static final Logger logger = getLogger(FileUtil.class); + private static final Logger LOGGER = Logger.getLogger(FileUtil.class); /** * returns a list of files found by the given regexp in the given folder @@ -86,40 +85,24 @@ public abstract class FileUtil { * @param source the file to copy from * @param destination the destination filename to copy the source file to * @return true, if the vile was copied, false, else + * + * @deprecated use Files.copy instead */ public static boolean copyFileTo(File source, File destination) { - FileInputStream fis = null; - FileOutputStream fos = null; - try { - fis = new FileInputStream(source); - fos = new FileOutputStream(destination); + try (FileInputStream fis = new FileInputStream(source); + FileOutputStream fos = new FileOutputStream(destination)) { byte[] buf = new byte[4096]; - int loaded; - while ((loaded = fis.read(buf)) > 0) { + int loaded = fis.read(buf); + while (loaded > 0) { fos.write(buf, 0, loaded); + loaded = fis.read(buf); } } catch (IOException e) { + LOGGER.debug(e.toString(), e); return false; - } finally { - if (fis != null) { - try { - fis.close(); - } catch (IOException ex) { - logger.error(ex.getMessage()); - logger.debug(getStackTraceString(ex)); - } - } - if (fos != null) { - try { - fos.close(); - } catch (IOException ex) { - logger.error(ex.getMessage()); - logger.debug(getStackTraceString(ex)); - } - } - } + return true; }