use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonIteratorImpl method readValue.
private IonValue readValue() {
IonType type = _reader.getType();
SymbolToken[] annotations = _reader.getTypeAnnotationSymbols();
IonValue v;
if (_reader.isNullValue()) {
v = _valueFactory.newNull(type);
} else {
switch(type) {
case NULL:
// Handled above
throw new IllegalStateException();
case BOOL:
v = _valueFactory.newBool(_reader.booleanValue());
break;
case INT:
v = _valueFactory.newInt(_reader.bigIntegerValue());
break;
case FLOAT:
v = _valueFactory.newFloat(_reader.doubleValue());
break;
case DECIMAL:
v = _valueFactory.newDecimal(_reader.decimalValue());
break;
case TIMESTAMP:
v = _valueFactory.newTimestamp(_reader.timestampValue());
break;
case STRING:
v = _valueFactory.newString(_reader.stringValue());
break;
case SYMBOL:
// TODO always pass the SID? Is it correct?
v = _valueFactory.newSymbol(_reader.symbolValue());
break;
case BLOB:
{
IonLob lob = _valueFactory.newNullBlob();
lob.setBytes(_reader.newBytes());
v = lob;
break;
}
case CLOB:
{
IonLob lob = _valueFactory.newNullClob();
lob.setBytes(_reader.newBytes());
v = lob;
break;
}
case STRUCT:
{
IonStruct struct = _valueFactory.newEmptyStruct();
_reader.stepIn();
while (_reader.next() != null) {
SymbolToken name = _reader.getFieldNameSymbol();
IonValue child = readValue();
struct.add(name, child);
}
_reader.stepOut();
v = struct;
break;
}
case LIST:
{
IonSequence seq = _valueFactory.newEmptyList();
_reader.stepIn();
while (_reader.next() != null) {
IonValue child = readValue();
seq.add(child);
}
_reader.stepOut();
v = seq;
break;
}
case SEXP:
{
IonSequence seq = _valueFactory.newEmptySexp();
_reader.stepIn();
while (_reader.next() != null) {
IonValue child = readValue();
seq.add(child);
}
_reader.stepOut();
v = seq;
break;
}
default:
throw new IllegalStateException();
}
}
// TODO this is too late in the case of system reading
// when v is a local symtab (it will get itself, not the prior symtab)
SymbolTable symtab = _reader.getSymbolTable();
((_Private_IonValue) v).setSymbolTable(symtab);
if (annotations.length != 0) {
((_Private_IonValue) v).setTypeAnnotationSymbols(annotations);
}
return v;
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonReaderBinaryIncremental method getSymbolToken.
/**
* Creates a SymbolToken representation of the given symbol ID.
* @param sid a symbol ID.
* @return a SymbolToken.
*/
private SymbolToken getSymbolToken(int sid) {
int symbolTableSize = maxSymbolId() + 1;
if (symbolTokensById == null) {
symbolTokensById = new ArrayList<SymbolToken>(symbolTableSize);
}
if (symbolTokensById.size() < symbolTableSize) {
for (int i = symbolTokensById.size(); i < symbolTableSize; i++) {
symbolTokensById.add(null);
}
}
if (sid >= symbolTableSize) {
throw new IonException("Symbol ID exceeds the max ID of the symbol table.");
}
SymbolToken token = symbolTokensById.get(sid);
if (token == null) {
String text = getSymbolString(sid, imports, symbols);
ImportLocation importLocation = null;
if (text == null) {
// Note: this will never be a system symbol.
if (sid > 0 && sid <= imports.getMaxId()) {
importLocation = imports.getImportLocation(sid);
} else {
// All symbols with unknown text in the local symbol range are equivalent to symbol zero.
sid = 0;
}
}
token = new SymbolTokenImpl(text, sid, importLocation);
symbolTokensById.set(sid, token);
}
return token;
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonReaderBinarySystemX method getTypeAnnotationSymbols.
public SymbolToken[] getTypeAnnotationSymbols() {
load_annotations();
int count = _annotation_count;
if (count == 0)
return SymbolToken.EMPTY_ARRAY;
SymbolTable symtab = getSymbolTable();
SymbolToken[] result = new SymbolToken[count];
for (int i = 0; i < count; i++) {
int sid = _annotation_ids[i];
String text = symtab.findKnownSymbol(sid);
result[i] = new SymbolTokenImpl(text, sid);
}
return result;
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonReaderBinaryIncremental method getTypeAnnotationSymbols.
@Override
public SymbolToken[] getTypeAnnotationSymbols() {
if (hasAnnotations) {
IntList annotationSids = getAnnotationSids();
SymbolToken[] annotationArray = new SymbolToken[annotationSids.size()];
for (int i = 0; i < annotationArray.length; i++) {
annotationArray[i] = getSymbolToken(annotationSids.get(i));
}
return annotationArray;
}
return SymbolToken.EMPTY_ARRAY;
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonReaderTextUserX method symbolValue.
@Override
public final SymbolToken symbolValue() {
SymbolToken symbol = super.symbolValue();
validateSymbolToken(symbol);
return symbol;
}
Aggregations