enhanced table method (used by almost all yacy api interfaces)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@8000 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 13 years ago
parent 4ad9fc2bff
commit eb9c9edb01

@ -55,6 +55,7 @@ import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipEntry;
@ -512,30 +513,33 @@ public final class FileUtils {
return table(new StringsIterator(br));
}
private final static Pattern escaped_equal = Pattern.compile("\\=", Pattern.LITERAL);
private final static Pattern escaped_newline = Pattern.compile("\\n", Pattern.LITERAL);
private final static Pattern escaped_backslash = Pattern.compile("\\", Pattern.LITERAL);
//private final static Pattern escaped_backslashbackslash = Pattern.compile("\\\\", Pattern.LITERAL);
//private final static Pattern escaped_equal = Pattern.compile("\\=");
//private final static Pattern escaped_newline = Pattern.compile("\\n");
//private final static Pattern escaped_backslash = Pattern.compile("\\");
public static ConcurrentHashMap<String, String> table(final Iterator<String> li) {
String line;
final ConcurrentHashMap<String, String> props = new ConcurrentHashMap<String, String>();
while (li.hasNext()) {
int pos = 0;
line = li.next().trim();
if (line.length() > 0 && line.charAt(0) == '#') continue; // exclude comments
do {
// search for unescaped =
pos = line.indexOf('=', pos+1);
} while ( pos > 0 && line.charAt(pos-1) == '\\');
if (pos > 0) {
//String key = escaped_equal.matcher(line.substring(0, pos).trim()).replaceAll("=");
final String key = line.substring(0, pos).trim().replace("\\=", "=").replace("\\n", "\n").replace("\\", "\\");
final String value = line.substring(pos + 1).trim().replace("\\n", "\n").replace("\\\\", "\\");
props.put(key, value);
}
}
return props;
}
String line;
final ConcurrentHashMap<String, String> props = new ConcurrentHashMap<String, String>();
while (li.hasNext()) {
int pos = 0;
line = li.next().trim();
if (line.length() > 0 && line.charAt(0) == '#') continue; // exclude comments
do {
// search for unescaped =
pos = line.indexOf('=', pos + 1);
} while ( pos > 0 && line.charAt(pos - 1) == '\\');
if (pos > 0) {
String key = escaped_equal.matcher(line.substring(0, pos).trim()).replaceAll("=");
key = escaped_newline.matcher(key).replaceAll("\n");
key = escaped_backslash.matcher(key).replaceAll("\\");
String value = escaped_newline.matcher(line.substring(pos + 1).trim()).replaceAll("\n");
value = value.replace("\\\\", "\\"); // does not work: escaped_backslashbackslash.matcher(value).replaceAll("\\");
props.put(key, value);
}
}
return props;
}
public static Map<String, String> table(final byte[] a) {
return table(strings(a));

@ -211,7 +211,7 @@ public final class yacy {
try {
sb = new Switchboard(dataHome, appHome, "defaults/yacy.init".replace("/", File.separator), newconf);
} catch (final RuntimeException e) {
Log.logSevere("STARTUP", "YaCy cannot start: " + e.getMessage());
Log.logSevere("STARTUP", "YaCy cannot start: " + e.getMessage(), e);
System.exit(-1);
}
//sbSync.V(); // signal that the sb reference was set

Loading…
Cancel
Save