Search in sources :

Example 76 with SymbolTable

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

the class IonBinaryWriterBuilderTest method testImportsNull.

@Test
public void testImportsNull() {
    SymbolTable f = Symtabs.CATALOG.getTable("fred", 1);
    SymbolTable[] symtabs = new SymbolTable[] { f };
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
    b.setImports(symtabs);
    b.setImports((SymbolTable[]) null);
    assertSame(null, b.getImports());
    b.setImports(new SymbolTable[0]);
    assertArrayEquals(new SymbolTable[0], b.getImports());
}
Also used : com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 77 with SymbolTable

use of com.amazon.ion.SymbolTable in project ion-hive-serde by amzn.

the class CatalogConfig method catalogFromReader.

private static IonCatalog catalogFromReader(final IonReader reader) {
    final SimpleCatalog catalog = new SimpleCatalog();
    while (reader.next() != null) {
        @SuppressWarnings("deprecated") final SymbolTable symbolTable = _Private_Utils.newSharedSymtab(reader, true);
        catalog.putTable(symbolTable);
    }
    return catalog;
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) SymbolTable(com.amazon.ion.SymbolTable)

Example 78 with SymbolTable

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

the class IonJavaCli method handleSymbolTableEvent.

// 
// 
// helper functions
// 
// 
private static void handleSymbolTableEvent(ProcessContext processContext, Event event, CommandArgs args, boolean isEmbedded) throws IOException {
    processContext.getIonWriter().close();
    ImportDescriptor[] imports = event.getImports();
    SymbolTable[] symbolTables = new SymbolTable[imports.length];
    for (int i = 0; i < imports.length; i++) {
        SymbolTable symbolTable = ION_SYSTEM.newSharedSymbolTable(imports[i].getImportName(), imports[i].getVersion(), null);
        symbolTables[i] = symbolTable;
    }
    if (!isEmbedded) {
        OutputStream out = args.getOutputFile() == null ? new NoCloseOutputStream(System.out) : new FileOutputStream(processContext.getFile(), true);
        processContext.setIonWriter(args.getOutputFormat().createIonWriterWithImports(out, symbolTables));
    } else {
        processContext.getEmbeddedOut().append(" ");
        processContext.setIonWriter(ION_TEXT_WRITER_BUILDER.withImports(symbolTables).build(processContext.getEmbeddedOut()));
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) SymbolTable(com.amazon.ion.SymbolTable) ImportDescriptor(com.amazon.tools.events.ImportDescriptor)

Example 79 with SymbolTable

use of com.amazon.ion.SymbolTable 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 80 with SymbolTable

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

Aggregations

SymbolTable (com.amazon.ion.SymbolTable)177 Test (org.junit.Test)105 IonValue (com.amazon.ion.IonValue)21 IonDatagram (com.amazon.ion.IonDatagram)18 com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable (com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable)17 SymbolToken (com.amazon.ion.SymbolToken)14 IonStruct (com.amazon.ion.IonStruct)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 IonWriter (com.amazon.ion.IonWriter)12 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)12 IonReader (com.amazon.ion.IonReader)11 IonSystem (com.amazon.ion.IonSystem)10 IOException (java.io.IOException)9 IonType (com.amazon.ion.IonType)8 ArrayList (java.util.ArrayList)7 IonException (com.amazon.ion.IonException)6 com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)6 com.amazon.ion.impl.bin._Private_IonRawWriter (com.amazon.ion.impl.bin._Private_IonRawWriter)6 IonCatalog (com.amazon.ion.IonCatalog)5 IonList (com.amazon.ion.IonList)5