Search in sources :

Example 16 with InvalidPropertiesFormatException

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);
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) InvalidPropertiesFormatException(java.util.InvalidPropertiesFormatException) Test(org.testng.annotations.Test)

Example 17 with InvalidPropertiesFormatException

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();
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InvalidPropertiesFormatException(java.util.InvalidPropertiesFormatException) BufferedReader(java.io.BufferedReader) LineNumberReader(java.io.LineNumberReader)

Example 18 with InvalidPropertiesFormatException

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);
        }
    }
}
Also used : InvalidPropertiesFormatException(java.util.InvalidPropertiesFormatException)

Aggregations

InvalidPropertiesFormatException (java.util.InvalidPropertiesFormatException)18 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 Properties (java.util.Properties)6 FileInputStream (java.io.FileInputStream)3 InputStreamReader (java.io.InputStreamReader)2 LineNumberReader (java.io.LineNumberReader)2 SQLException (java.sql.SQLException)2 SAXException (jdk.internal.org.xml.sax.SAXException)2 SAXParserImpl (jdk.internal.util.xml.impl.SAXParserImpl)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 SAXException (org.xml.sax.SAXException)2 ClientException (com.iplanet.services.cdm.ClientException)1 SSOException (com.iplanet.sso.SSOException)1 SMSException (com.sun.identity.sm.SMSException)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1