Allow String/File/Path/etc objects to be used as file path parameter

This commit is contained in:
Reinhard Pointner 2017-01-21 21:08:05 +08:00
parent 1207e092dc
commit 282f48158e
1 changed files with 6 additions and 6 deletions

View File

@ -64,7 +64,7 @@ public class ExpressionFormatFunctions {
return stream(c1, null, cN).map(Objects::toString).map(s -> q + s.replace(q, r) + q).collect(joining(" ")); return stream(c1, null, cN).map(Objects::toString).map(s -> q + s.replace(q, r) + q).collect(joining(" "));
} }
public static Map<String, String> csv(String path) throws IOException { public static Map<String, String> csv(Object path) throws IOException {
Pattern[] delimiter = { TAB, SEMICOLON }; Pattern[] delimiter = { TAB, SEMICOLON };
Map<String, String> map = new LinkedHashMap<String, String>(); Map<String, String> map = new LinkedHashMap<String, String>();
for (String line : readLines(path)) { for (String line : readLines(path)) {
@ -79,19 +79,19 @@ public class ExpressionFormatFunctions {
return map; return map;
} }
public static List<String> readLines(String path) throws IOException { public static List<String> readLines(Object path) throws IOException {
return FileUtilities.readLines(getUserFile(path)); return FileUtilities.readLines(getUserFile(path));
} }
public static Object readXml(String path) throws Exception { public static Object readXml(Object path) throws Exception {
return new XmlSlurper().parse(getUserFile(path)); return new XmlSlurper().parse(getUserFile(path));
} }
public static File getUserFile(String path) { public static File getUserFile(Object path) {
File f = new File(path); File f = new File(path.toString());
if (!f.isAbsolute()) { if (!f.isAbsolute()) {
f = ApplicationFolder.UserHome.resolve(path); f = ApplicationFolder.UserHome.resolve(f.getPath());
} }
if (isMacSandbox()) { if (isMacSandbox()) {