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);
}
}
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);
}
}
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;
}
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;
}
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();
}
Aggregations