migrated to Java 8
This commit is contained in:
@ -6,6 +6,8 @@
|
||||
*/
|
||||
package de.muehlencord.shared.util;
|
||||
|
||||
import static java.lang.System.getProperties;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern@muehlencord.de
|
||||
@ -27,7 +29,7 @@ public abstract class OSUtil {
|
||||
* @return an OS_xxxx constants identifiying the operating system the current JVM is running on;
|
||||
*/
|
||||
public static int getOperationSystem() {
|
||||
String osName = System.getProperties().getProperty("os.name");
|
||||
String osName = getProperties().getProperty("os.name");
|
||||
if (osName != null) {
|
||||
osName = osName.toUpperCase();
|
||||
if (osName.contains("WINDOWS")) {
|
||||
|
||||
@ -8,6 +8,7 @@ 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;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -16,7 +17,7 @@ import org.apache.log4j.Logger;
|
||||
public abstract class StringUtil {
|
||||
|
||||
/** the logging object */
|
||||
private static final Logger logger = Logger.getLogger(StringUtil.class);
|
||||
private static final Logger logger = getLogger(StringUtil.class);
|
||||
|
||||
/**
|
||||
* returns the given string in ISO-8859-1 encoding
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
package de.muehlencord.shared.util.file;
|
||||
|
||||
import de.muehlencord.shared.util.StringUtil;
|
||||
import static de.muehlencord.shared.util.StringUtil.getStackTraceString;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
@ -12,9 +13,11 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.Format;
|
||||
import java.util.Arrays;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -23,7 +26,7 @@ import org.apache.log4j.Logger;
|
||||
public abstract class FileUtil {
|
||||
|
||||
/** the logging object */
|
||||
private static final Logger logger = Logger.getLogger(FileUtil.class);
|
||||
private static final Logger logger = getLogger(FileUtil.class);
|
||||
|
||||
/**
|
||||
* returns a list of files found by the given regexp in the given folder
|
||||
@ -35,7 +38,7 @@ public abstract class FileUtil {
|
||||
* @throws FileHandlingException if the given directory cannot be found
|
||||
*/
|
||||
public static List<File> getFilesFromDirecotry(final String directory, final String regEx) throws FileHandlingException {
|
||||
List<File> returnValue = new LinkedList<File>();
|
||||
List<File> returnValue = new LinkedList<>();
|
||||
File dir = new File(directory);
|
||||
if (!dir.exists()) {
|
||||
throw new FileHandlingException("Directory " + directory + " does not exist");
|
||||
@ -44,18 +47,14 @@ public abstract class FileUtil {
|
||||
throw new FileHandlingException(directory + " is not a directory");
|
||||
}
|
||||
|
||||
FileFilter ff = new FileFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
boolean isFile = pathname.isFile();
|
||||
boolean match = pathname.toString().matches(regEx);
|
||||
return isFile && match;
|
||||
}
|
||||
FileFilter ff = (File pathname) -> {
|
||||
boolean isFile = pathname.isFile();
|
||||
boolean match = pathname.toString().matches(regEx);
|
||||
return isFile && match;
|
||||
};
|
||||
File[] files = dir.listFiles(ff);
|
||||
if (files != null) {
|
||||
returnValue.addAll(Arrays.asList(files));
|
||||
returnValue.addAll(asList(files));
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
@ -106,7 +105,7 @@ public abstract class FileUtil {
|
||||
fis.close();
|
||||
} catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
if (fos != null) {
|
||||
@ -114,7 +113,7 @@ public abstract class FileUtil {
|
||||
fos.close();
|
||||
} catch (IOException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
logger.debug(StringUtil.getStackTraceString(ex));
|
||||
logger.debug(getStackTraceString(ex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
*/
|
||||
package de.muehlencord.shared.util;
|
||||
|
||||
import static de.muehlencord.shared.util.OSUtil.getOperationSystem;
|
||||
import static java.lang.System.getProperties;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@ -19,8 +21,8 @@ public class OSUtilTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetOS() {
|
||||
String osName = System.getProperties().getProperty("os.name").toUpperCase();
|
||||
int os = OSUtil.getOperationSystem();
|
||||
String osName = getProperties().getProperty("os.name").toUpperCase();
|
||||
int os = getOperationSystem();
|
||||
|
||||
switch (osName) {
|
||||
case "LINUX":
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package de.muehlencord.shared.util;
|
||||
|
||||
import static de.muehlencord.shared.util.StringUtil.getValueBetweenKeywords;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import static org.junit.Assert.*;
|
||||
@ -16,7 +17,7 @@ public class StringUtilTest extends DefaultTest {
|
||||
public void testGetValueBetweenKeywords() throws ParseException, IOException {
|
||||
String content = readContentFromFile("test.txt");
|
||||
|
||||
String ipAddress = StringUtil.getValueBetweenKeywords(content, "The IP", "has just");
|
||||
String ipAddress = getValueBetweenKeywords(content, "The IP", "has just");
|
||||
assertEquals("ipAddress", "222.184.230.118", ipAddress);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
*/
|
||||
package de.muehlencord.shared.util.file;
|
||||
|
||||
import static de.muehlencord.shared.util.file.FileUtil.getFilesFromDirecotry;
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
@ -29,7 +30,7 @@ public class FileUtilTest {
|
||||
URL url = getClass().getResource("testfile.txt");
|
||||
File testFile = new File(url.getFile());
|
||||
|
||||
List<File> fileList = FileUtil.getFilesFromDirecotry(testFile.getParent(), ".*.java");
|
||||
List<File> fileList = getFilesFromDirecotry(testFile.getParent(), ".*.java");
|
||||
Iterator<File> it = fileList.iterator();
|
||||
while (it.hasNext()) {
|
||||
System.out.println(it.next());
|
||||
|
||||
Reference in New Issue
Block a user