fixed sonar bugs
This commit is contained in:
@ -1,12 +1,7 @@
|
|||||||
/*
|
|
||||||
* OSUtil.java
|
|
||||||
*
|
|
||||||
* Created on 10. Dezember 2007, 16:50
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.muehlencord.shared.util;
|
package de.muehlencord.shared.util;
|
||||||
|
|
||||||
import static java.lang.System.getProperties;
|
import static java.lang.System.getProperties;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -31,7 +26,7 @@ public abstract class OSUtil {
|
|||||||
public static int getOperationSystem() {
|
public static int getOperationSystem() {
|
||||||
String osName = getProperties().getProperty("os.name");
|
String osName = getProperties().getProperty("os.name");
|
||||||
if (osName != null) {
|
if (osName != null) {
|
||||||
osName = osName.toUpperCase();
|
osName = osName.toUpperCase(Locale.getDefault());
|
||||||
if (osName.contains("WINDOWS")) {
|
if (osName.contains("WINDOWS")) {
|
||||||
return OS_WINDOWS;
|
return OS_WINDOWS;
|
||||||
} else if (osName.contains("LINUX")) {
|
} else if (osName.contains("LINUX")) {
|
||||||
|
|||||||
@ -1,14 +1,8 @@
|
|||||||
/*
|
|
||||||
* StringUtil.java
|
|
||||||
*
|
|
||||||
* Created on 4. Mai 2007, 12:36
|
|
||||||
*/
|
|
||||||
package de.muehlencord.shared.util;
|
package de.muehlencord.shared.util;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import org.apache.log4j.Logger;
|
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 {
|
public abstract class StringUtil {
|
||||||
|
|
||||||
/** the logging object */
|
/** 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
|
* returns the given string in ISO-8859-1 encoding
|
||||||
@ -32,7 +26,7 @@ public abstract class StringUtil {
|
|||||||
byte[] b = input.getBytes("UTF-8");
|
byte[] b = input.getBytes("UTF-8");
|
||||||
return new String(b, "ISO-8859-1");
|
return new String(b, "ISO-8859-1");
|
||||||
} catch (UnsupportedEncodingException ex) {
|
} 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);
|
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
|
* @return the stackstrace as one string
|
||||||
*/
|
*/
|
||||||
public static String getStackTraceString(Throwable ex) {
|
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();
|
StackTraceElement[] stack = ex.getStackTrace();
|
||||||
for (StackTraceElement stack1 : stack) {
|
for (StackTraceElement currentElement : stack) {
|
||||||
logString += (stack1.toString()) + "\n";
|
sb.append (currentElement.toString());
|
||||||
|
sb.append ("\n");
|
||||||
}
|
}
|
||||||
return logString;
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,11 +66,12 @@ public abstract class StringUtil {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
String returnValue = s;
|
StringBuilder sb = new StringBuilder();
|
||||||
while (s.length() < length) {
|
sb.append (s);
|
||||||
returnValue += " ";
|
while (sb.toString().length() < length) {
|
||||||
|
sb.append (" ");
|
||||||
}
|
}
|
||||||
return returnValue;
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import static java.util.Arrays.asList;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import static org.apache.log4j.Logger.getLogger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -28,7 +27,7 @@ public abstract class FileUtil {
|
|||||||
/**
|
/**
|
||||||
* the logging object
|
* 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
|
* 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 source the file to copy from
|
||||||
* @param destination the destination filename to copy the source file to
|
* @param destination the destination filename to copy the source file to
|
||||||
* @return true, if the vile was copied, false, else
|
* @return true, if the vile was copied, false, else
|
||||||
|
*
|
||||||
|
* @deprecated use Files.copy instead
|
||||||
*/
|
*/
|
||||||
public static boolean copyFileTo(File source, File destination) {
|
public static boolean copyFileTo(File source, File destination) {
|
||||||
FileInputStream fis = null;
|
try (FileInputStream fis = new FileInputStream(source);
|
||||||
FileOutputStream fos = null;
|
FileOutputStream fos = new FileOutputStream(destination)) {
|
||||||
try {
|
|
||||||
fis = new FileInputStream(source);
|
|
||||||
fos = new FileOutputStream(destination);
|
|
||||||
|
|
||||||
byte[] buf = new byte[4096];
|
byte[] buf = new byte[4096];
|
||||||
int loaded;
|
int loaded = fis.read(buf);
|
||||||
while ((loaded = fis.read(buf)) > 0) {
|
while (loaded > 0) {
|
||||||
fos.write(buf, 0, loaded);
|
fos.write(buf, 0, loaded);
|
||||||
|
loaded = fis.read(buf);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
LOGGER.debug(e.toString(), e);
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user