use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonSystemLite method load_value_helper.
private IonValueLite load_value_helper(IonReader reader, boolean isTopLevel) {
boolean symbol_is_present = false;
IonType t = reader.getType();
if (t == null) {
return null;
}
IonValueLite v;
if (reader.isNullValue()) {
v = newNull(t);
} else {
switch(t) {
case BOOL:
v = newBool(reader.booleanValue());
break;
case INT:
// TODO amzn/ion-java/issues/9 Inefficient since we can't determine the size
// of the integer in order to avoid making BigIntegers.
v = newInt(reader.bigIntegerValue());
break;
case FLOAT:
v = newFloat(reader.doubleValue());
break;
case DECIMAL:
v = newDecimal(reader.decimalValue());
break;
case TIMESTAMP:
v = newTimestamp(reader.timestampValue());
break;
case SYMBOL:
v = newSymbol(reader.symbolValue());
symbol_is_present = true;
break;
case STRING:
v = newString(reader.stringValue());
break;
case CLOB:
v = newClob(reader.newBytes());
break;
case BLOB:
v = newBlob(reader.newBytes());
break;
case LIST:
v = newEmptyList();
break;
case SEXP:
v = newEmptySexp();
break;
case STRUCT:
v = newEmptyStruct();
break;
default:
throw new IonException("unexpected type encountered reading value: " + t.toString());
}
}
// Forget any incoming SIDs on field names.
if (!isTopLevel && reader.isInStruct()) {
SymbolToken token = reader.getFieldNameSymbol();
String text = token.getText();
if (text != null && token.getSid() != UNKNOWN_SYMBOL_ID) {
token = newSymbolToken(text, UNKNOWN_SYMBOL_ID);
}
v.setFieldNameSymbol(token);
symbol_is_present = true;
}
// Forget any incoming SIDs on annotations.
// This is a fresh array so we can modify it:
SymbolToken[] annotations = reader.getTypeAnnotationSymbols();
if (annotations.length != 0) {
for (int i = 0; i < annotations.length; i++) {
SymbolToken token = annotations[i];
String text = token.getText();
if (text != null && token.getSid() != UNKNOWN_SYMBOL_ID) {
annotations[i] = newSymbolToken(text, UNKNOWN_SYMBOL_ID);
}
}
v.setTypeAnnotationSymbols(annotations);
symbol_is_present = true;
}
if (!reader.isNullValue()) {
switch(t) {
case BOOL:
case INT:
case FLOAT:
case DECIMAL:
case TIMESTAMP:
case SYMBOL:
case STRING:
case CLOB:
case BLOB:
break;
case LIST:
case SEXP:
case STRUCT:
// fieldname and annotations off of the parent container
if (load_children((IonContainerLite) v, reader)) {
symbol_is_present = true;
}
break;
default:
throw new IonException("unexpected type encountered reading value: " + t.toString());
}
}
if (symbol_is_present) {
v._isSymbolPresent(true);
}
return v;
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonSystemLite method clone.
@SuppressWarnings("unchecked")
public <T extends IonValue> T clone(T value) throws IonException {
// Use "fast clone" when the system is the same.
if (value.getSystem() == this) {
return (T) value.clone();
}
if (value instanceof IonDatagram) {
IonDatagram datagram = newDatagram();
IonWriter writer = _Private_IonWriterFactory.makeWriter(datagram);
IonReader reader = makeSystemReader(value.getSystem(), value);
try {
writer.writeValues(reader);
} catch (IOException e) {
throw new IonException(e);
}
return (T) datagram;
}
IonReader reader = newReader(value);
reader.next();
return (T) newValue(reader);
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonValueLite method writeTo.
final void writeTo(IonWriter writer, SymbolTableProvider symbolTableProvider) {
if (writer.isInStruct() && !((_Private_IonWriter) writer).isFieldNameSet()) {
SymbolToken tok = getFieldNameSymbol(symbolTableProvider);
if (tok == null) {
throw new IllegalStateException("Field name not set");
}
writer.setFieldNameSymbol(tok);
}
SymbolToken[] annotations = getTypeAnnotationSymbols(symbolTableProvider);
writer.setTypeAnnotationSymbols(annotations);
try {
writeBodyTo(writer, symbolTableProvider);
} catch (IOException e) {
throw new IonException(e);
}
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonValueLite method toString.
public String toString(IonTextWriterBuilder writerBuilder) {
StringBuilder buf = new StringBuilder(1024);
try {
IonWriter writer = writerBuilder.build(buf);
writeTo(writer);
writer.finish();
} catch (IOException e) {
throw new IonException(e);
}
return buf.toString();
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class JarInfo method loadBuildProperties.
// TODO writeTo(IonWriter)
// ========================================================================
private void loadBuildProperties(List<Manifest> manifests) throws IonException {
boolean propertiesLoaded = false;
for (Manifest manifest : manifests) {
boolean success = tryLoadBuildProperties(manifest);
if (success && propertiesLoaded) {
// In the event of conflicting manifests, fail instead of risking returning incorrect version info.
throw new IonException("Found multiple manifests with ion-java version info on the classpath.");
}
propertiesLoaded |= success;
}
if (!propertiesLoaded) {
throw new IonException("Unable to locate manifest with ion-java version info on the classpath.");
}
}
Aggregations