Search in sources :

Example 6 with Decimal

use of com.amazon.ion.Decimal 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

Decimal (com.amazon.ion.Decimal)6 BigDecimal (java.math.BigDecimal)5 BigInteger (java.math.BigInteger)4 Timestamp (com.amazon.ion.Timestamp)2 BinaryTest (com.amazon.ion.BinaryTest)1 IonDecimal (com.amazon.ion.IonDecimal)1 IonType (com.amazon.ion.IonType)1 SymbolToken (com.amazon.ion.SymbolToken)1 SavePoint (com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint)1 MathContext (java.math.MathContext)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1