summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java
diff options
context:
space:
mode:
authorstudent <student@192.168.1.186>2017-04-07 11:34:00 -0400
committerstudent <student@192.168.1.186>2017-04-07 11:34:00 -0400
commit7692fa077a84972231948354d3f0de99f27a9ad7 (patch)
treea7539aff7732339f7655c35f2c2c07723618127b /BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java
parent63d88eb8db1f7a6d5924ec2a8b7f462373d5ac9a (diff)
Fix property bugs
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java33
1 files changed, 22 insertions, 11 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java b/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java
index e3b0122..a43b16a 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/ioutils/SimpleProperties.java
@@ -15,7 +15,7 @@ import java.util.Set;
*
*/
public class SimpleProperties implements Map<String, String> {
- private static Map<String, String> props;
+ private Map<String, String> props;
/**
* Create a new set of simple properties.
@@ -32,33 +32,37 @@ public class SimpleProperties implements Map<String, String> {
* All leading/trailing spaces from the name & body are removed.
*
* @param is
- * The stream to read from.
+ * The stream to read from.
*
* @param allowDuplicates
- * Whether or not duplicate keys should be allowed.
+ * Whether or not duplicate keys should be allowed.
*/
public void loadFrom(InputStream is, boolean allowDuplicates) {
- try(Scanner scn = new Scanner(is)) {
- while(scn.hasNextLine()) {
+ try (Scanner scn = new Scanner(is)) {
+ while (scn.hasNextLine()) {
String ln = scn.nextLine().trim();
/*
* Skip blank lines/comments
*/
- if(ln.equals("")) continue;
- if(ln.equals("#")) continue;
+ if (ln.equals(""))
+ continue;
+ if (ln.startsWith("#"))
+ continue;
int sepIdx = ln.indexOf(' ');
- if(sepIdx == -1) {
- throw new NoSuchElementException(
- "Properties must be a name, a space, then the body");
+ if (sepIdx == -1) {
+ String fmt = "Properties must be a name, a space, then the body.\n\tOffending line is '%s'";
+ String msg = String.format(fmt, ln);
+
+ throw new NoSuchElementException(msg);
}
String name = ln.substring(0, sepIdx).trim();
String body = ln.substring(sepIdx).trim();
- if(!allowDuplicates && containsKey(name)) {
+ if (!allowDuplicates && containsKey(name)) {
String msg = String.format("Duplicate key '%s'", name);
throw new IllegalStateException(msg);
@@ -67,6 +71,13 @@ public class SimpleProperties implements Map<String, String> {
put(name, body);
}
}
+
+ System.out.println("Read properties:");
+ for (Entry<String, String> entry : entrySet()) {
+ System.out.printf("\t'%s'\t'%s'\n", entry.getKey(), entry.getValue());
+ }
+ System.out.println();
+
}
@Override