Search in sources :

Example 21 with AtlasException

use of org.apache.jena.atlas.AtlasException in project jena by apache.

the class LogCtl method setJavaLoggingDft.

public static void setJavaLoggingDft() {
    try {
        InputStream details = new ByteArrayInputStream(defaultProperties.getBytes("UTF-8"));
        java.util.logging.LogManager.getLogManager().readConfiguration(details);
    } catch (Exception ex) {
        throw new AtlasException(ex);
    }
}
Also used : AtlasException(org.apache.jena.atlas.AtlasException) AtlasException(org.apache.jena.atlas.AtlasException)

Example 22 with AtlasException

use of org.apache.jena.atlas.AtlasException in project jena by apache.

the class LogCtl method setJavaLogging.

public static void setJavaLogging(String file) {
    try {
        InputStream details = new FileInputStream(file);
        details = new BufferedInputStream(details);
        java.util.logging.LogManager.getLogManager().readConfiguration(details);
    } catch (Exception ex) {
        throw new AtlasException(ex);
    }
}
Also used : AtlasException(org.apache.jena.atlas.AtlasException) AtlasException(org.apache.jena.atlas.AtlasException)

Example 23 with AtlasException

use of org.apache.jena.atlas.AtlasException in project jena by apache.

the class InStreamASCII method read.

@Override
public int read(char[] cbuf, int off, int len) {
    for (int i = off; i < off + len; i++) {
        int x = read();
        if (x == -1) {
            if (i == off)
                return -1;
            return (i - off);
        }
        if (x > 128)
            throw new AtlasException("Illegal ASCII character : " + x);
        cbuf[i] = (char) x;
    }
    return len;
}
Also used : AtlasException(org.apache.jena.atlas.AtlasException)

Example 24 with AtlasException

use of org.apache.jena.atlas.AtlasException in project jena by apache.

the class InStreamUTF8 method readMultiBytes.

private static int readMultiBytes(InputStreamBuffered input, int start, int len) {
    int x = start;
    for (int i = 0; i < len - 1; i++) {
        int x2 = input.advance();
        if (x2 == -1)
            throw new AtlasException("Premature end to UTF-8 sequence at end of input");
        if ((x2 & 0xC0) != 0x80)
            //throw new AtlasException("Illegal UTF-8 processing character "+count+": "+x2) ;
            throw new AtlasException(String.format("Illegal UTF-8 processing character: 0x%04X", x2));
        // 6 bits of x2
        x = (x << 6) | (x2 & 0x3F);
    }
    return x;
}
Also used : AtlasException(org.apache.jena.atlas.AtlasException)

Example 25 with AtlasException

use of org.apache.jena.atlas.AtlasException in project jena by apache.

the class EscapeStr method unescape.

// Main worker function for unescaping strings.
public static String unescape(String s, char escape, boolean pointCodeOnly) {
    int i = s.indexOf(escape);
    if (i == -1)
        return s;
    // Dump the initial part straight into the string buffer
    StringBuilder sb = new StringBuilder(s.substring(0, i));
    for (; i < s.length(); i++) {
        char ch = s.charAt(i);
        if (ch != escape) {
            sb.append(ch);
            continue;
        }
        // Escape
        if (i >= s.length() - 1)
            throw new AtlasException("Illegal escape at end of string");
        char ch2 = s.charAt(i + 1);
        i = i + 1;
        // \\u and \\U
        if (ch2 == 'u') {
            // i points to the \ so i+6 is next character
            if (i + 4 >= s.length())
                throw new AtlasException("\\u escape too short");
            int x = Hex.hexStringToInt(s, i + 1, 4);
            sb.append((char) x);
            // Jump 1 2 3 4 -- already skipped \ and u
            i = i + 4;
            continue;
        }
        if (ch2 == 'U') {
            // i points to the \ so i+6 is next character
            if (i + 8 >= s.length())
                throw new AtlasException("\\U escape too short");
            int x = Hex.hexStringToInt(s, i + 1, 8);
            // Convert to UTF-16 codepoint pair.
            sb.append((char) x);
            // Jump 1 2 3 4 5 6 7 8 -- already skipped \ and u
            i = i + 8;
            continue;
        }
        if (pointCodeOnly) {
            sb.append('\\');
            sb.append(ch2);
            i = i + 1;
            continue;
        }
        // Not just codepoints.  Must be a legal escape.
        char ch3 = 0;
        switch(ch2) {
            case 'n':
                ch3 = '\n';
                break;
            case 't':
                ch3 = '\t';
                break;
            case 'r':
                ch3 = '\r';
                break;
            case 'b':
                ch3 = '\b';
                break;
            case 'f':
                ch3 = '\f';
                break;
            case '\'':
                ch3 = '\'';
                break;
            case '\"':
                ch3 = '\"';
                break;
            case '\\':
                ch3 = '\\';
                break;
            default:
                throw new AtlasException("Unknown escape: \\" + ch2);
        }
        sb.append(ch3);
    }
    return sb.toString();
}
Also used : AtlasException(org.apache.jena.atlas.AtlasException)

Aggregations

AtlasException (org.apache.jena.atlas.AtlasException)27 IOException (java.io.IOException)5 FileNotFoundException (java.io.FileNotFoundException)4 File (java.io.File)3 InputStream (java.io.InputStream)3 RiotParseException (org.apache.jena.riot.RiotParseException)3 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 Token (org.apache.jena.riot.tokens.Token)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 Iterator (java.util.Iterator)1 InStreamUTF8 (org.apache.jena.atlas.io.InStreamUTF8)1 InputStreamBuffered (org.apache.jena.atlas.io.InputStreamBuffered)1 IteratorResourceClosing (org.apache.jena.atlas.iterator.IteratorResourceClosing)1 ProgressMonitor (org.apache.jena.atlas.lib.ProgressMonitor)1 BlockMgr (org.apache.jena.tdb.base.block.BlockMgr)1 FileSet (org.apache.jena.tdb.base.file.FileSet)1 Location (org.apache.jena.tdb.base.file.Location)1