use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderTextRawTokensX method nextToken.
public final int nextToken() throws IOException {
int t = -1;
int c, c2;
if (_unfinished_token) {
c = skip_to_end(null);
} else {
c = skip_over_whitespace();
}
_unfinished_token = true;
switch(c) {
case -1:
return next_token_finish(IonTokenConstsX.TOKEN_EOF, true);
case '/':
unread_char(c);
return next_token_finish(IonTokenConstsX.TOKEN_SYMBOL_OPERATOR, true);
case ':':
c2 = read_char();
if (c2 != ':') {
unread_char(c2);
return next_token_finish(IonTokenConstsX.TOKEN_COLON, true);
}
return next_token_finish(IonTokenConstsX.TOKEN_DOUBLE_COLON, true);
case '{':
c2 = read_char();
if (c2 != '{') {
unread_char(c2);
// CAS: 9 nov 2009
return next_token_finish(IonTokenConstsX.TOKEN_OPEN_BRACE, true);
}
return next_token_finish(IonTokenConstsX.TOKEN_OPEN_DOUBLE_BRACE, true);
case '}':
// two structs together. see tryForDoubleBrace() below
return next_token_finish(IonTokenConstsX.TOKEN_CLOSE_BRACE, false);
case '[':
// CAS: 9 nov 2009
return next_token_finish(IonTokenConstsX.TOKEN_OPEN_SQUARE, true);
case ']':
return next_token_finish(IonTokenConstsX.TOKEN_CLOSE_SQUARE, false);
case '(':
// CAS: 9 nov 2009
return next_token_finish(IonTokenConstsX.TOKEN_OPEN_PAREN, true);
case ')':
return next_token_finish(IonTokenConstsX.TOKEN_CLOSE_PAREN, false);
case ',':
return next_token_finish(IonTokenConstsX.TOKEN_COMMA, false);
case '.':
c2 = read_char();
unread_char(c2);
if (IonTokenConstsX.isValidExtendedSymbolCharacter(c2)) {
unread_char('.');
return next_token_finish(IonTokenConstsX.TOKEN_SYMBOL_OPERATOR, true);
}
return next_token_finish(IonTokenConstsX.TOKEN_DOT, false);
case '\'':
if (is_2_single_quotes_helper()) {
return next_token_finish(IonTokenConstsX.TOKEN_STRING_TRIPLE_QUOTE, true);
}
// unread_char(c);
return next_token_finish(IonTokenConstsX.TOKEN_SYMBOL_QUOTED, true);
case '+':
if (// this will consume the inf if it succeeds
peek_inf_helper(c)) {
return next_token_finish(IonTokenConstsX.TOKEN_FLOAT_INF, false);
}
unread_char(c);
return next_token_finish(IonTokenConstsX.TOKEN_SYMBOL_OPERATOR, true);
case '#':
case '<':
case '>':
case '*':
case '=':
case '^':
case '&':
case '|':
case '~':
case ';':
case '!':
case '?':
case '@':
case '%':
case '`':
unread_char(c);
return next_token_finish(IonTokenConstsX.TOKEN_SYMBOL_OPERATOR, true);
case '"':
return next_token_finish(IonTokenConstsX.TOKEN_STRING_DOUBLE_QUOTE, true);
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '$':
case '_':
unread_char(c);
return next_token_finish(IonTokenConstsX.TOKEN_SYMBOL_IDENTIFIER, true);
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
t = scan_for_numeric_type(c);
unread_char(c);
return next_token_finish(t, true);
case '-':
// see if we have a number or what might be an extended symbol
c2 = read_char();
unread_char(c2);
if (IonTokenConstsX.isDigit(c2)) {
t = scan_negative_for_numeric_type(c);
unread_char(c);
return next_token_finish(t, true);
} else if (// this will consume the inf if it succeeds
peek_inf_helper(c)) {
return next_token_finish(IonTokenConstsX.TOKEN_FLOAT_MINUS_INF, false);
} else {
unread_char(c);
return next_token_finish(IonTokenConstsX.TOKEN_SYMBOL_OPERATOR, true);
}
default:
// throws
bad_token_start(c);
}
throw new IonException("invalid state: next token switch shouldn't exit");
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderTextSystemX method newBytes.
public byte[] newBytes() {
ensureLob("newBytes");
byte[] bytes;
int len;
try {
len = load_lob_contents();
} catch (IOException e) {
throw new IonException(e);
}
bytes = new byte[len];
System.arraycopy(_lob_bytes, 0, bytes, 0, len);
return bytes;
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonTokenConstsX method decodeSid.
public static int decodeSid(CharSequence sidToken) {
assert sidToken.charAt(0) == '$';
int length = sidToken.length();
assert length > 1;
String digits = sidToken.subSequence(1, length).toString();
try {
return Integer.parseInt(digits);
} catch (Exception e) {
throw new IonException(String.format("Unable to parse SID %s", digits), e);
}
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonTokenReader method next.
private Type next(int c, boolean is_in_expression) throws IOException {
int c2;
t = Type.none;
isIncomplete = false;
switch(c) {
case -1:
return (t = Type.eof);
case '{':
c2 = read();
if (c2 == '{') {
return (t = Type.tOpenDoubleCurly);
}
unread(c2);
return (t = Type.tOpenCurly);
case '}':
return (t = Type.tCloseCurly);
case '[':
return (t = Type.tOpenSquare);
case ']':
return (t = Type.tCloseSquare);
case '(':
return (t = Type.tOpenParen);
case ')':
return (t = Type.tCloseParen);
case ',':
return (t = Type.tComma);
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return readNumber(c);
case '\"':
inQuotedContent = true;
// anything in quotes isn't a keyword
this.keyword = Type.none;
return scanString(c, _Private_IonConstants.lnIsVarLen - 1);
case '\'':
c2 = read();
if (c2 == '\'') {
c2 = read();
if (c2 == '\'') {
return scanLongString();
}
this.unread(c2);
// restore c2 for the next unread
c2 = '\'';
}
this.unread(c2);
inQuotedContent = true;
return scanIdentifier(c);
case '+':
c2 = read();
if (c2 == 'i') {
c2 = read();
if (c2 == 'n') {
c2 = read();
if (c2 == 'f') {
return (t = Type.kwPosInf);
}
this.unread(c2);
c2 = 'n';
}
this.unread(c2);
c2 = 'i';
}
this.unread(c2);
if (is_in_expression) {
return scanOperator(c);
}
// break to error
break;
case '-':
c2 = read();
if (c2 >= '0' && c2 <= '9') {
this.unread(c2);
return readNumber(c);
}
if (c2 == 'i') {
c2 = read();
if (c2 == 'n') {
c2 = read();
if (c2 == 'f') {
return (t = Type.kwNegInf);
}
this.unread(c2);
c2 = 'n';
}
this.unread(c2);
c2 = 'i';
}
this.unread(c2);
if (is_in_expression) {
return scanOperator(c);
}
// break to error
break;
default:
if (IonTextUtils.isIdentifierStart(c)) {
return scanIdentifier(c);
}
if (is_in_expression && isOperatorPart(c)) {
return scanOperator(c);
}
}
String message = "Unexpected character " + printCodePointAsString(c) + " encountered at line " + this.getLineNumber() + " column " + this.getColumn();
throw new IonException(message);
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonTokenReader method scanString.
public Type scanString(int c, int maxlookahead) throws IOException {
// reset out local value buffer
resetValue();
if (c != '\"') {
throw new IonException("Programmer error! Only a quote should get you here.");
}
endquote = '\"';
sizedloop: while (maxlookahead-- > 0) {
switch((c = this.read())) {
// TODO deoptimize, throw exception
case -1:
break sizedloop;
case '\"':
break sizedloop;
case '\n':
throw new IonException("unexpected line terminator encountered in quoted string");
case '\\':
c = readEscapedCharacter(this.in, false);
// throws UnexpectedEofException on EOF
if (c != EMPTY_ESCAPE_SEQUENCE) {
value.appendCodePoint(c);
}
break;
default:
// c could be part of a surrogate pair so we can't use
// appendCodePoint()
value.append((char) c);
break;
}
}
if (maxlookahead != -1 && c == '\"') {
// this is the normal, non-longline case so we're just done
closeString();
} else {
// we're not at the closing quote, so this is an incomplete
// string which will have to be read to the end ... later
leaveOpenString(c, false);
}
return Type.constString;
}
Aggregations