use of java.util.InvalidPropertiesFormatException in project open-ecard by ecsec.
the class ExceptionUtilsTest method testMatchPath.
@Test
public void testMatchPath() {
// create random exceptions, nest them and check if the path matches
Throwable root = new NullPointerException();
Throwable ex = new InvalidAlgorithmParameterException(root);
ex = new InvalidPropertiesFormatException(ex);
NullPointerException result = ExceptionUtils.matchPath(ex, NullPointerException.class, InvalidAlgorithmParameterException.class);
Assert.assertNotNull(result);
Assert.assertEquals(result, root);
}
use of java.util.InvalidPropertiesFormatException in project ceylon by eclipse.
the class MemoPushbackReader method process.
/**
* Starts the actual processing of the input
* @throws IOException Either actual file-related IO exceptions or
* InvalidPropertiesFormatException when problems with the file format
* are detected
*/
public void process() throws IOException {
section = null;
try {
counterdr = new LineNumberReader(new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8"))));
reader = new MemoPushbackReader(counterdr);
listener.setup();
Token tok;
skipWhitespace(true);
flushWhitespace();
while ((tok = peekToken()) != Token.eof) {
switch(tok) {
case section:
handleSection();
break;
case option:
if (section != null) {
handleOption();
} else {
throw new InvalidPropertiesFormatException("Option without section in configuration file at line " + (counterdr.getLineNumber() + 1));
}
break;
case comment:
skipToNextLine();
listener.onComment(reader.getAndClearMemo());
break;
case eol:
skipToNextLine();
listener.onWhitespace(reader.getAndClearMemo());
break;
default:
throw new InvalidPropertiesFormatException("Unexpected token in configuration file at line " + (counterdr.getLineNumber() + 1));
}
skipWhitespace(true);
flushWhitespace();
}
listener.cleanup();
} finally {
if (reader != null) {
reader.close();
}
}
}
use of java.util.InvalidPropertiesFormatException in project ceylon by eclipse.
the class MemoPushbackReader method handleOptionValue.
private void handleOptionValue(String optName) throws IOException {
StringBuilder str = new StringBuilder();
skipWhitespace(false);
boolean hasQuote = gobble('\"');
int c;
while ((c = reader.read()) != -1) {
if (c == '"') {
reader.unread(c);
break;
} else if (isNewLineChar(c)) {
reader.unread(c);
break;
} else if (isCommentChar(c) && !hasQuote) {
reader.unread(c);
break;
} else if (c == '\\') {
int c2 = reader.read();
if (c2 == '\\') {
// Do nothing
} else if (c2 == '\"') {
c = c2;
} else if (c2 == 't') {
c = '\t';
} else if (c2 == 'n') {
c = '\n';
} else if (isNewLineChar(c2)) {
skipNewLine(c2);
c = '\n';
} else {
throw new InvalidPropertiesFormatException("Illegal escape character in configuration file at line " + (counterdr.getLineNumber() + 1));
}
}
str.append((char) c);
}
String res = str.toString();
if (hasQuote) {
expect('\"');
listener.onOption(optName, res, reader.getAndClearMemo());
} else {
String memo = reader.getAndClearMemo();
// Is there still some whitespace?
String ws = rightTrimmings(res);
if (!ws.isEmpty()) {
listener.onOption(optName, res.trim(), memo.trim());
listener.onWhitespace(ws);
} else {
listener.onOption(optName, res.trim(), memo);
}
}
}
Aggregations