System.out.println(" ... already set to " + setString);
System.out.println(" ... in the file '" + conf.getCanonicalPath() + "'");
return; // *** EARLY RETURN ***
}
final TextFile textFile = new TextFile(conf.getAbsolutePath());
if (textFile.isEmpty()) {
throw new Exception("File is empty? '" +
conf.getAbsolutePath() + "'");
}
boolean replaced = false;
final int size = textFile.size();
for (int i = 0; i < size; i++) {
final String line = (String) textFile.get(i);
if (line != null && line.trim().length() > 0) {
if (line.trim().startsWith(keyword)) {
final String newline;
if (newvalue == null) {
newline = "#" + keyword + "=";
} else {
newline = keyword + "=" + newvalue.trim();
}
textFile.set(i, newline);
replaced = true;
break;
}
}
}
if (!replaced) {
// race condition with getProperty() on file contents?
throw new Exception("Could not alter the configuration file, no '" +
keyword + "' setting present in the file '" +
conf.getAbsolutePath() + "' (?)");
}
textFile.writeFile(conf);
System.out.println("[*] The '" + keyword + "' configuration was:");
if (newvalue == null) {
System.out.println(" ... commented out");
} else if (newvalue.trim().length() == 0) {