Search in sources :

Example 6 with IonList

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

the class IonWriterTestCase method testWriteValuesWithSymtab.

@Test
public void testWriteValuesWithSymtab() throws Exception {
    SymbolTable fredSymtab = Symtabs.register(Symtabs.FRED_NAME, 1, catalog());
    SymbolTable gingerSymtab = Symtabs.register(Symtabs.GINGER_NAME, 1, catalog());
    String gingerSym = gingerSymtab.findKnownSymbol(1);
    // First setup some data to be copied.
    IonDatagram dg = system().newDatagram(gingerSymtab);
    dg.add().newSymbol(gingerSym);
    IonReader r = system().newReader(dg.getBytes());
    // Now copy that data into a non-top-level context
    iw = makeWriter(fredSymtab);
    iw.stepIn(IonType.LIST);
    iw.writeValues(r);
    iw.stepOut();
    IonDatagram result = reload();
    IonList l = (IonList) result.get(0);
    assertEquals(1, l.size());
    IonSymbol s = (IonSymbol) l.get(0);
    // Should've assigned a new SID
    checkSymbol(gingerSym, s);
}
Also used : IonSymbol(com.amazon.ion.IonSymbol) IonDatagram(com.amazon.ion.IonDatagram) IonList(com.amazon.ion.IonList) IonReader(com.amazon.ion.IonReader) SymbolTable(com.amazon.ion.SymbolTable) IonString(com.amazon.ion.IonString) Test(org.junit.Test)

Example 7 with IonList

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

the class IonReaderTextSystemX method getIonValue.

public IonValue getIonValue(IonSystem sys) {
    if (isNullValue()) {
        switch(_value_type) {
            case NULL:
                return sys.newNull();
            case BOOL:
                return sys.newNullBool();
            case INT:
                return sys.newNullInt();
            case FLOAT:
                return sys.newNullFloat();
            case DECIMAL:
                return sys.newNullDecimal();
            case TIMESTAMP:
                return sys.newNullTimestamp();
            case SYMBOL:
                return sys.newNullSymbol();
            case STRING:
                return sys.newNullString();
            case CLOB:
                return sys.newNullClob();
            case BLOB:
                return sys.newNullBlob();
            case LIST:
                return sys.newNullList();
            case SEXP:
                return sys.newNullSexp();
            case STRUCT:
                return sys.newNullString();
            default:
                throw new IonException("unrecognized type encountered");
        }
    }
    switch(_value_type) {
        case NULL:
            return sys.newNull();
        case BOOL:
            return sys.newBool(booleanValue());
        case INT:
            return sys.newInt(longValue());
        case FLOAT:
            return sys.newFloat(doubleValue());
        case DECIMAL:
            return sys.newDecimal(decimalValue());
        case TIMESTAMP:
            IonTimestamp t = sys.newNullTimestamp();
            Timestamp ti = timestampValue();
            t.setValue(ti);
            return t;
        case SYMBOL:
            return sys.newSymbol(stringValue());
        case STRING:
            return sys.newString(stringValue());
        case CLOB:
            IonClob clob = sys.newNullClob();
            // FIXME inefficient: both newBytes and setBytes copy the data
            clob.setBytes(newBytes());
            return clob;
        case BLOB:
            IonBlob blob = sys.newNullBlob();
            // FIXME inefficient: both newBytes and setBytes copy the data
            blob.setBytes(newBytes());
            return blob;
        case LIST:
            IonList list = sys.newNullList();
            fillContainerList(sys, list);
            return list;
        case SEXP:
            IonSexp sexp = sys.newNullSexp();
            fillContainerList(sys, sexp);
            return sexp;
        case STRUCT:
            IonStruct struct = sys.newNullStruct();
            fillContainerStruct(sys, struct);
            return struct;
        default:
            throw new IonException("unrecognized type encountered");
    }
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonSexp(com.amazon.ion.IonSexp) IonException(com.amazon.ion.IonException) IonTimestamp(com.amazon.ion.IonTimestamp) IonList(com.amazon.ion.IonList) IonClob(com.amazon.ion.IonClob) IonBlob(com.amazon.ion.IonBlob) Timestamp(com.amazon.ion.Timestamp) IonTimestamp(com.amazon.ion.IonTimestamp)

Example 8 with IonList

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

the class SymbolTableStructCache method addSymbol.

/**
 * Adds a new symbol table with the given symbol ID to the IonStruct's 'symbols' list.
 * @param symbolName can be null when there's a gap in the local symbols list.
 * @param sid the symbol ID to assign to the new symbol.
 */
void addSymbol(String symbolName, int sid) {
    assert sid >= firstLocalSid;
    ValueFactory sys = image.getSystem();
    IonValue syms = image.get(SYMBOLS);
    // the symbols field if necessary.
    while (syms != null && syms.getType() != IonType.LIST) {
        image.remove(syms);
        syms = image.get(SYMBOLS);
    }
    if (syms == null) {
        syms = sys.newEmptyList();
        image.put(SYMBOLS, syms);
    }
    int thisOffset = sid - firstLocalSid;
    IonValue name = sys.newString(symbolName);
    ((IonList) syms).add(thisOffset, name);
}
Also used : IonValue(com.amazon.ion.IonValue) IonList(com.amazon.ion.IonList) ValueFactory(com.amazon.ion.ValueFactory)

Example 9 with IonList

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

the class _Private_CurriedValueFactory method newEmptyList.

public IonList newEmptyList() {
    IonList v = myFactory.newEmptyList();
    handle(v);
    return v;
}
Also used : IonList(com.amazon.ion.IonList)

Example 10 with IonList

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

the class _Private_CurriedValueFactory method newNullList.

// -------------------------------------------------------------------------
public IonList newNullList() {
    IonList v = myFactory.newNullList();
    handle(v);
    return v;
}
Also used : IonList(com.amazon.ion.IonList)

Aggregations

IonList (com.amazon.ion.IonList)28 IonStruct (com.amazon.ion.IonStruct)13 Test (org.junit.Test)10 SymbolTable (com.amazon.ion.SymbolTable)5 IonDatagram (com.amazon.ion.IonDatagram)4 IonFloat (com.amazon.ion.IonFloat)3 IonReader (com.amazon.ion.IonReader)3 IonSexp (com.amazon.ion.IonSexp)3 IonString (com.amazon.ion.IonString)3 IonSymbol (com.amazon.ion.IonSymbol)3 IonBlob (com.amazon.ion.IonBlob)2 IonClob (com.amazon.ion.IonClob)2 IonTimestamp (com.amazon.ion.IonTimestamp)2 IonValue (com.amazon.ion.IonValue)2 BlobTest (com.amazon.ion.BlobTest)1 ClobTest (com.amazon.ion.ClobTest)1 IntTest (com.amazon.ion.IntTest)1 IonBool (com.amazon.ion.IonBool)1 IonDecimal (com.amazon.ion.IonDecimal)1 IonException (com.amazon.ion.IonException)1