Search in sources :

Example 6 with SymbolTable

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

the class BinaryWriterWithLocalSymtabsTest method testConstructionWithLocalSymbolsAndOneImports.

@Test
public void testConstructionWithLocalSymbolsAndOneImports() throws Exception {
    SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
    checkConstructionWithLocalSymbolsAndImports(LOCAL_SYMBOLS_ABC, fred1);
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 7 with SymbolTable

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

the class IonReaderBinaryIncremental method pop_passed_symbol_table.

@Override
public SymbolTable pop_passed_symbol_table() {
    SymbolTable currentSymbolTable = getSymbolTable();
    if (currentSymbolTable == symbolTableLastTransferred) {
        // be returned twice.
        return null;
    }
    symbolTableLastTransferred = currentSymbolTable;
    return symbolTableLastTransferred;
}
Also used : SymbolTable(com.amazon.ion.SymbolTable)

Example 8 with SymbolTable

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

the class IonJavaCli method ionStreamToEventStream.

private static void ionStreamToEventStream(IonReader ionReader, CommandType commandType, SymbolTable curTable, ReadContext readContext) throws IOException {
    if (ionReader.getType() == null)
        return;
    do {
        if (ionReader.isNullValue()) {
            IonValue value = ION_SYSTEM.newValue(ionReader);
            value.clearTypeAnnotations();
            readContext.getEventStream().add(new Event(EventType.SCALAR, ionReader.getType(), ionReader.getFieldNameSymbol(), ionReader.getTypeAnnotationSymbols(), value, null, ionReader.getDepth()));
            continue;
        }
        if (!isSameSymbolTable(ionReader.getSymbolTable(), curTable)) {
            curTable = ionReader.getSymbolTable();
            ImportDescriptor[] imports = symbolTableToImports(curTable.getImportedTables());
            if (commandType != CommandType.COMPARE) {
                readContext.getEventStream().add(new Event(EventType.SYMBOL_TABLE, null, null, null, null, imports, 0));
            }
        }
        if (isEmbeddedStream(ionReader)) {
            // get current Ion type and depth
            IonType curType = ionReader.getType();
            int curDepth = ionReader.getDepth();
            // write a Container_Start event and step in
            readContext.getEventStream().add(ionStreamToEvent(ionReader));
            ionReader.stepIn();
            while (ionReader.next() != null) {
                if (ionReader.getType() != IonType.STRING) {
                    throw new IonException("Elements of embedded streams sets must be strings.");
                }
                String stream = ionReader.stringValue();
                try (IonReader tempIonReader = IonReaderBuilder.standard().build(stream)) {
                    SymbolTable symbolTable = tempIonReader.getSymbolTable();
                    while (tempIonReader.next() != null) {
                        ionStreamToEventStream(tempIonReader, commandType, symbolTable, readContext);
                    }
                }
                readContext.getEventStream().add(new Event(EventType.STREAM_END, null, null, null, null, null, 0));
            }
            // write a Container_End event and step out
            readContext.getEventStream().add(new Event(EventType.CONTAINER_END, curType, null, null, null, null, curDepth));
            ionReader.stepOut();
        } else if (IonType.isContainer(ionReader.getType())) {
            // get current Ion type and depth
            IonType curType = ionReader.getType();
            int curDepth = ionReader.getDepth();
            // write a Container_Start event and step in
            readContext.getEventStream().add(ionStreamToEvent(ionReader));
            ionReader.stepIn();
            // recursive call
            ionReader.next();
            ionStreamToEventStream(ionReader, commandType, curTable, readContext);
            // write a Container_End event and step out
            readContext.getEventStream().add(new Event(EventType.CONTAINER_END, curType, null, null, null, null, curDepth));
            ionReader.stepOut();
        } else {
            readContext.getEventStream().add(ionStreamToEvent(ionReader));
        }
    } while (ionReader.next() != null);
    ;
}
Also used : IonValue(com.amazon.ion.IonValue) IonType(com.amazon.ion.IonType) IonException(com.amazon.ion.IonException) IonReader(com.amazon.ion.IonReader) Event(com.amazon.tools.events.Event) SymbolTable(com.amazon.ion.SymbolTable) ImportDescriptor(com.amazon.tools.events.ImportDescriptor)

Example 9 with SymbolTable

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

the class IonJavaCli method getEventStream.

private static void getEventStream(IonReader ionReader, CommandType commandType, ReadContext readContext) throws IOException {
    SymbolTable curTable = ionReader.getSymbolTable();
    boolean isEventStream = isEventStream(ionReader);
    if (isEventStream) {
        readContext.setState(ErrorType.WRITE);
        while (ionReader.next() != null) {
            Event event = eventStreamToEvent(ionReader);
            if (event.getEventType() == EventType.SYMBOL_TABLE && commandType == CommandType.COMPARE) {
                continue;
            }
            readContext.getEventStream().add(event);
        }
    } else {
        readContext.setState(ErrorType.READ);
        ionStreamToEventStream(ionReader, commandType, curTable, readContext);
        readContext.getEventStream().add(new Event(EventType.STREAM_END, null, null, null, null, null, 0));
    }
    if (commandType == CommandType.PROCESS) {
        validateEventStream(readContext.getEventStream());
    }
    return;
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) Event(com.amazon.tools.events.Event)

Example 10 with SymbolTable

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

the class IonReaderBinaryUserX method pop_passed_symbol_table.

@Override
public SymbolTable pop_passed_symbol_table() {
    if (_symbol_table_top <= 0) {
        return null;
    }
    _symbol_table_top--;
    SymbolTable symbols = _symbol_table_stack[_symbol_table_top];
    _symbol_table_stack[_symbol_table_top] = null;
    return symbols;
}
Also used : 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