use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderTextRawX method token_contents_load.
protected final StringBuilder token_contents_load(int token_type) throws IOException {
StringBuilder sb = _current_value_buffer;
boolean clob_chars_only;
int c;
if (_current_value_buffer_loaded) {
return sb;
} else if (_current_value_save_point_loaded) {
assert (!_scanner.isUnfinishedToken() && !_current_value_save_point.isClear());
// _scanner.load_save_point_contents( _current_value_save_point, sb);
_scanner.save_point_activate(_current_value_save_point);
switch(token_type) {
default:
_scanner.load_raw_characters(sb);
break;
case IonTokenConstsX.TOKEN_SYMBOL_IDENTIFIER:
_scanner.load_symbol_identifier(sb);
_value_type = IonType.SYMBOL;
break;
case IonTokenConstsX.TOKEN_SYMBOL_OPERATOR:
_scanner.load_symbol_operator(sb);
_value_type = IonType.SYMBOL;
break;
case IonTokenConstsX.TOKEN_SYMBOL_QUOTED:
clob_chars_only = (IonType.CLOB == _value_type);
_scanner.load_single_quoted_string(sb, clob_chars_only);
_value_type = IonType.SYMBOL;
break;
case IonTokenConstsX.TOKEN_STRING_DOUBLE_QUOTE:
clob_chars_only = (IonType.CLOB == _value_type);
_scanner.load_double_quoted_string(sb, clob_chars_only);
_value_type = IonType.STRING;
break;
case IonTokenConstsX.TOKEN_STRING_TRIPLE_QUOTE:
clob_chars_only = (IonType.CLOB == _value_type);
_scanner.load_triple_quoted_string(sb, clob_chars_only);
_value_type = IonType.STRING;
break;
}
_scanner.save_point_deactivate(_current_value_save_point);
_current_value_buffer_loaded = true;
} else {
_scanner.save_point_start(_current_value_save_point);
switch(token_type) {
case IonTokenConstsX.TOKEN_UNKNOWN_NUMERIC:
case IonTokenConstsX.TOKEN_INT:
case IonTokenConstsX.TOKEN_BINARY:
case IonTokenConstsX.TOKEN_HEX:
case IonTokenConstsX.TOKEN_FLOAT:
case IonTokenConstsX.TOKEN_DECIMAL:
case IonTokenConstsX.TOKEN_TIMESTAMP:
_value_type = _scanner.load_number(sb);
break;
case IonTokenConstsX.TOKEN_SYMBOL_IDENTIFIER:
_scanner.load_symbol_identifier(sb);
_value_type = IonType.SYMBOL;
break;
case IonTokenConstsX.TOKEN_SYMBOL_OPERATOR:
_scanner.load_symbol_operator(sb);
_value_type = IonType.SYMBOL;
break;
case IonTokenConstsX.TOKEN_SYMBOL_QUOTED:
clob_chars_only = (IonType.CLOB == _value_type);
c = _scanner.load_single_quoted_string(sb, clob_chars_only);
if (c == UnifiedInputStreamX.EOF) {
// String message = "EOF encountered before closing single quote";
// parse_error(message);
_scanner.unexpected_eof();
}
_value_type = IonType.SYMBOL;
break;
case IonTokenConstsX.TOKEN_STRING_DOUBLE_QUOTE:
clob_chars_only = (IonType.CLOB == _value_type);
c = _scanner.load_double_quoted_string(sb, clob_chars_only);
if (c == UnifiedInputStreamX.EOF) {
// String message = "EOF encountered before closing single quote";
// parse_error(message);
_scanner.unexpected_eof();
}
_value_type = IonType.STRING;
break;
case IonTokenConstsX.TOKEN_STRING_TRIPLE_QUOTE:
clob_chars_only = (IonType.CLOB == _value_type);
c = _scanner.load_triple_quoted_string(sb, clob_chars_only);
if (c == UnifiedInputStreamX.EOF) {
// String message = "EOF encountered before closing single quote";
// parse_error(message);
_scanner.unexpected_eof();
}
_value_type = IonType.STRING;
break;
default:
String message = "unexpected token " + IonTokenConstsX.getTokenName(token_type) + " encountered";
throw new IonException(message);
}
_current_value_save_point.markEnd();
_current_value_save_point_loaded = true;
_current_value_buffer_loaded = true;
tokenValueIsFinished();
}
return sb;
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderTextRawX method stepIn.
public void stepIn() {
if (_value_type == null || _eof) {
throw new IllegalStateException();
}
switch(_value_type) {
case STRUCT:
case LIST:
case SEXP:
break;
default:
throw new IllegalStateException("Unexpected value type: " + _value_type);
}
int new_state = get_state_at_container_start(_value_type);
set_state(new_state);
push_container_state(_value_type);
_scanner.tokenIsFinished();
try {
finish_value(null);
} catch (IOException e) {
throw new IonException(e);
}
if (_v.isNull()) {
_eof = true;
// there are no contents in a null container
_has_next_called = true;
}
_value_type = null;
if (_debug)
System.out.println("stepInto() new depth: " + getDepth());
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonManagedBinaryWriterGoodTest method allGoodFiles.
@Test
public void allGoodFiles() throws Exception {
byte[] testData = _Private_Utils.loadFileBytes(myTestFile);
IonReader reader = IonReaderBuilder.standard().build(testData);
writer.writeValues(reader);
reader.close();
writer.finish();
final byte[] data = writer.getBytes();
final IonValue actual;
try {
actual = system().getLoader().load(data);
} catch (final Exception e) {
throw new IonException("Bad generated data:\n" + hexDump(data), e);
}
final IonValue expected = system().getLoader().load(testData);
assertEquals(expected, actual);
additionalValueAssertions(actual);
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonRawBinaryWriterTest method assertValue.
protected final void assertValue(final String literal) throws IOException {
writer.finish();
final byte[] data = writer.getBytes();
final IonValue actual;
try {
actual = system().singleValue(data);
} catch (final Exception e) {
throw new IonException("Bad generated data:\n" + hexDump(data), e);
}
final IonValue expected = system().singleValue(literal);
assertEquals(expected, actual);
additionalValueAssertions(actual);
// prepare for next value
writer.reset();
writeIVMIfPossible();
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class LocalSymbolTable method readOneImport.
/**
* Returns a {@link SymbolTable} representation of a single import
* declaration from the passed-in reader and catalog.
*
* @return
* symbol table representation of the import; null if the import
* declaration is malformed
*/
private static SymbolTable readOneImport(IonReader ionRep, IonCatalog catalog) {
assert (ionRep.getType() == IonType.STRUCT);
String name = null;
int version = -1;
int maxid = -1;
ionRep.stepIn();
IonType t;
while ((t = ionRep.next()) != null) {
if (ionRep.isNullValue())
continue;
SymbolToken symTok = ionRep.getFieldNameSymbol();
int field_id = symTok.getSid();
if (field_id == UNKNOWN_SYMBOL_ID) {
// this is a user defined reader or a pure DOM
// we fall back to text here
final String fieldName = ionRep.getFieldName();
field_id = getSidForSymbolTableField(fieldName);
}
switch(field_id) {
case NAME_SID:
if (t == IonType.STRING) {
name = ionRep.stringValue();
}
break;
case VERSION_SID:
if (t == IonType.INT) {
version = ionRep.intValue();
}
break;
case MAX_ID_SID:
if (t == IonType.INT) {
maxid = ionRep.intValue();
}
break;
default:
// we just ignore anything else as "open content"
break;
}
}
ionRep.stepOut();
// Ignore import clauses with malformed name field.
if (name == null || name.length() == 0 || name.equals(ION)) {
return null;
}
if (version < 1) {
version = 1;
}
SymbolTable itab = null;
if (catalog != null) {
itab = catalog.getTable(name, version);
}
if (maxid < 0) {
if (itab == null || version != itab.getVersion()) {
String message = "Import of shared table " + IonTextUtils.printString(name) + " lacks a valid max_id field, but an exact match was not" + " found in the catalog";
if (itab != null) {
message += " (found version " + itab.getVersion() + ")";
}
// TODO custom exception
throw new IonException(message);
}
// Exact match is found, but max_id is undefined in import
// declaration, set max_id to largest sid of shared symtab
maxid = itab.getMaxId();
}
if (itab == null) {
assert maxid >= 0;
// Construct substitute table with max_id undefined symbols
itab = new SubstituteSymbolTable(name, version, maxid);
} else if (itab.getVersion() != version || itab.getMaxId() != maxid) {
// A match was found BUT specs are not an exact match
// Construct a substitute with correct specs, containing the
// original import table that was found
itab = new SubstituteSymbolTable(itab, version, maxid);
}
return itab;
}
Aggregations