Search in sources :

Example 41 with SymbolToken

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;
}
Also used : IonValue(com.amazon.ion.IonValue) IonStruct(com.amazon.ion.IonStruct) IonType(com.amazon.ion.IonType) SymbolToken(com.amazon.ion.SymbolToken) IonLob(com.amazon.ion.IonLob) IonSequence(com.amazon.ion.IonSequence) SymbolTable(com.amazon.ion.SymbolTable)

Example 42 with SymbolToken

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;
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) IonException(com.amazon.ion.IonException)

Example 43 with SymbolToken

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;
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) SymbolTable(com.amazon.ion.SymbolTable)

Example 44 with SymbolToken

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;
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) IntList(com.amazon.ion.impl.bin.IntList)

Example 45 with SymbolToken

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;
}
Also used : SymbolToken(com.amazon.ion.SymbolToken)

Aggregations

SymbolToken (com.amazon.ion.SymbolToken)68 SymbolTable (com.amazon.ion.SymbolTable)14 com.amazon.ion.impl._Private_Utils.newSymbolToken (com.amazon.ion.impl._Private_Utils.newSymbolToken)13 IonType (com.amazon.ion.IonType)10 IonValue (com.amazon.ion.IonValue)10 IonException (com.amazon.ion.IonException)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 IonStruct (com.amazon.ion.IonStruct)4 IOException (java.io.IOException)4 Event (com.amazon.tools.events.Event)3 EventType (com.amazon.tools.events.EventType)3 FakeSymbolToken (com.amazon.ion.FakeSymbolToken)2 IonDatagram (com.amazon.ion.IonDatagram)2 IonSequence (com.amazon.ion.IonSequence)2 IonString (com.amazon.ion.IonString)2 UnknownSymbolException (com.amazon.ion.UnknownSymbolException)2 SavePoint (com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint)2 ImportDescriptor (com.amazon.tools.events.ImportDescriptor)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2