in container/openejb-core/src/main/java/org/apache/openejb/util/SuperProperties.java [427:635]
public synchronized void load(final InputStream in) throws IOException {
// never null, when empty we are processing the white space at the beginning of the line
StringBuilder key = new StringBuilder();
// null when processing key
StringBuilder value = null;
// never null, contains the comment for the property or nothing if no comment
StringBuilder comment = new StringBuilder();
// never null, contains attributes for a property
LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
int indent = 0;
boolean globalIndentSet = false;
int commentIndent = -1;
boolean globalCommentIndentSet = false;
// true when processing the separator between a key and value
boolean inSeparator = false;
while (true) {
int nextByte = decodeNextCharacter(in);
if (nextByte == EOF) {
break;
}
char nextChar = (char) (nextByte & 0xff);
switch (nextByte) {
case ' ':
case '\t':
//
// End of key if parsing key
//
// if parsing the key, this is the end of the key
if (key.length() > 0 && value == null) {
inSeparator = true;
value = new StringBuilder();
continue;
}
break;
case ':':
case '=':
//
// End of key
//
if (inSeparator) {
inSeparator = false;
continue;
}
if (value == null) {
value = new StringBuilder();
continue;
}
break;
case LINE_ENDING:
//
// End of Line
//
if (key.length() > 0) {
// add property
put(key.toString(), value == null ? "" : value.toString());
// add comment
if (comment.length() > 0) {
setComment(key.toString(), comment.toString());
comment = new StringBuilder();
}
// add attributes
this.attributes.put(normalize(key.toString()), attributes);
attributes = new LinkedHashMap<>();
// set line indent
if (!globalIndentSet) {
setIndent(indent);
globalIndentSet = true;
}
indent = 0;
}
key = new StringBuilder();
value = null;
continue;
case '#':
case '!':
//
// Comment
//
if (key.length() == 0) {
// set global line indent
if (!globalIndentSet) {
setIndent(indent);
globalIndentSet = true;
}
indent = 0;
// read comment Line
final StringBuilder commentLine = new StringBuilder();
int commentLineIndent = 0;
boolean inIndent = true;
while (true) {
nextByte = in.read();
if (nextByte < 0) {
break;
}
nextChar = (char) nextByte; // & 0xff
if (inIndent && nextChar == ' ') {
commentLineIndent++;
commentLine.append(' ');
} else if (inIndent && nextChar == '\t') {
commentLineIndent += 4;
commentLine.append(" ");
} else if (nextChar == '\r' || nextChar == '\n') {
break;
} else {
inIndent = false;
commentLine.append(nextChar);
}
}
// Determine indent
if (comment.length() == 0) {
// if this is a new comment block, the comment indent size for this
// block is based the first line of the comment
commentIndent = commentLineIndent;
if (!globalCommentIndentSet) {
setCommentIndent(commentIndent);
globalCommentIndentSet = true;
}
}
commentLineIndent = Math.min(commentIndent, commentLineIndent);
if (commentLine.toString().trim().startsWith("@")) {
// process property attribute
final String attribute = commentLine.toString().trim().substring(1);
final String[] parts = attribute.split("=", 2);
final String attributeName = parts[0].trim();
final String attributeValue = parts.length == 2 ? parts[1].trim() : "";
attributes.put(attributeName, attributeValue);
} else {
// append comment
if (comment.length() != 0) {
comment.append(lineSeparator);
}
comment.append(commentLine.toString().substring(commentLineIndent));
}
continue;
}
break;
}
if (nextByte >= 0 && Character.isWhitespace(nextChar)) {
// count leading white space
if (key.length() == 0) {
if (nextChar == '\t') {
indent += 4;
} else {
indent++;
}
}
// if key length == 0 or value length == 0
if (key.length() == 0 || value == null || value.length() == 0) {
continue;
}
}
// Decode encoded separator characters
switch (nextByte) {
case ENCODED_EQUALS:
nextChar = '=';
break;
case ENCODED_COLON:
nextChar = ':';
break;
case ENCODED_SPACE:
nextChar = ' ';
break;
case ENCODED_TAB:
nextChar = '\t';
break;
case ENCODED_NEWLINE:
nextChar = '\n';
break;
case ENCODED_CARRIAGE_RETURN:
nextChar = '\r';
break;
}
inSeparator = false;
if (value == null) {
key.append(nextChar);
} else {
value.append(nextChar);
}
}
// if buffer has data, there is a property we still need toadd
if (key.length() > 0) {
// add property
put(key.toString(), value == null ? "" : value.toString());
// add comment
if (comment.length() > 0) {
setComment(key.toString(), comment.toString());
}
// add attributes
this.attributes.put(normalize(key.toString()), attributes);
// set line indent
if (!globalIndentSet) {
setIndent(indent);
}
}
}