Search in sources :

Example 61 with SymbolToken

use of com.amazon.ion.SymbolToken in project ion-java by amzn.

the class IonManagedBinaryWriter method setFieldName.

// Current Value Meta
public void setFieldName(final String name) {
    if (!isInStruct()) {
        throw new IllegalStateException("IonWriter.setFieldName() must be called before writing a value into a struct.");
    }
    if (name == null) {
        throw new NullPointerException("Null field name is not allowed.");
    }
    final SymbolToken token = intern(name);
    user.setFieldNameSymbol(token);
}
Also used : SymbolToken(com.amazon.ion.SymbolToken)

Example 62 with SymbolToken

use of com.amazon.ion.SymbolToken in project ion-java by amzn.

the class IonManagedBinaryWriter method addTypeAnnotation.

public void addTypeAnnotation(final String annotation) {
    final SymbolToken token = intern(annotation);
    user.addTypeAnnotationSymbol(token);
}
Also used : SymbolToken(com.amazon.ion.SymbolToken)

Example 63 with SymbolToken

use of com.amazon.ion.SymbolToken in project ion-java by amzn.

the class IonValueLite method addTypeAnnotation.

public /* synchronized */
void addTypeAnnotation(String annotation) {
    checkForLock();
    if (annotation == null || annotation.length() < 1) {
        throw new IllegalArgumentException("a user type annotation must be a non-empty string");
    }
    // we don't add duplicate annotations
    if (hasTypeAnnotation(annotation))
        return;
    SymbolToken sym = newSymbolToken(annotation, UNKNOWN_SYMBOL_ID);
    int old_len = (_annotations == null) ? 0 : _annotations.length;
    if (old_len > 0) {
        for (int ii = 0; ii < old_len; ii++) {
            if (_annotations[ii] == null) {
                _annotations[ii] = sym;
                return;
            }
        }
    }
    int new_len = (old_len == 0) ? 1 : old_len * 2;
    SymbolToken[] temp = new SymbolToken[new_len];
    if (old_len > 0) {
        System.arraycopy(_annotations, 0, temp, 0, old_len);
    }
    _annotations = temp;
    _annotations[old_len] = sym;
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) com.amazon.ion.impl._Private_Utils.newSymbolToken(com.amazon.ion.impl._Private_Utils.newSymbolToken)

Example 64 with SymbolToken

use of com.amazon.ion.SymbolToken in project ion-java by amzn.

the class IonValueLite method removeTypeAnnotation.

public void removeTypeAnnotation(String annotation) {
    checkForLock();
    if (annotation != null && annotation.length() > 0) {
        int pos = findTypeAnnotation(annotation);
        if (pos < 0) {
            return;
        }
        int ii;
        for (ii = pos; ii < _annotations.length - 1; ii++) {
            SymbolToken a = _annotations[ii + 1];
            if (a == null) {
                break;
            }
            _annotations[ii] = a;
        }
        if (ii < _annotations.length) {
            _annotations[ii] = null;
        }
    }
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) com.amazon.ion.impl._Private_Utils.newSymbolToken(com.amazon.ion.impl._Private_Utils.newSymbolToken)

Example 65 with SymbolToken

use of com.amazon.ion.SymbolToken in project ion-java by amzn.

the class AbstractIonWriter method writeValueRecursive.

public final void writeValueRecursive(final IonReader reader) throws IOException {
    final IonType type = reader.getType();
    final SymbolToken fieldName = reader.getFieldNameSymbol();
    if (fieldName != null && !isFieldNameSet() && isInStruct()) {
        setFieldNameSymbol(fieldName);
    }
    final SymbolToken[] annotations = reader.getTypeAnnotationSymbols();
    if (annotations.length > 0) {
        setTypeAnnotationSymbols(annotations);
    }
    if (reader.isNullValue()) {
        writeNull(type);
        return;
    }
    switch(type) {
        case BOOL:
            final boolean booleanValue = reader.booleanValue();
            writeBool(booleanValue);
            break;
        case INT:
            switch(reader.getIntegerSize()) {
                case INT:
                    final int intValue = reader.intValue();
                    writeInt(intValue);
                    break;
                case LONG:
                    final long longValue = reader.longValue();
                    writeInt(longValue);
                    break;
                case BIG_INTEGER:
                    final BigInteger bigIntegerValue = reader.bigIntegerValue();
                    writeInt(bigIntegerValue);
                    break;
                default:
                    throw new IllegalStateException();
            }
            break;
        case FLOAT:
            final double doubleValue = reader.doubleValue();
            writeFloat(doubleValue);
            break;
        case DECIMAL:
            final Decimal decimalValue = reader.decimalValue();
            writeDecimal(decimalValue);
            break;
        case TIMESTAMP:
            final Timestamp timestampValue = reader.timestampValue();
            writeTimestamp(timestampValue);
            break;
        case SYMBOL:
            final SymbolToken symbolToken = reader.symbolValue();
            writeSymbolToken(symbolToken);
            break;
        case STRING:
            final String stringValue = reader.stringValue();
            writeString(stringValue);
            break;
        case CLOB:
            final byte[] clobValue = reader.newBytes();
            writeClob(clobValue);
            break;
        case BLOB:
            final byte[] blobValue = reader.newBytes();
            writeBlob(blobValue);
            break;
        case LIST:
        case SEXP:
        case STRUCT:
            reader.stepIn();
            stepIn(type);
            while (reader.next() != null) {
                writeValue(reader);
            }
            stepOut();
            reader.stepOut();
            break;
        default:
            throw new IllegalStateException("Unexpected type: " + type);
    }
}
Also used : IonType(com.amazon.ion.IonType) SymbolToken(com.amazon.ion.SymbolToken) Timestamp(com.amazon.ion.Timestamp) Decimal(com.amazon.ion.Decimal) BigInteger(java.math.BigInteger)

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