Search in sources :

Example 6 with com.amazon.ion.impl.bin._Private_IonRawWriter

use of com.amazon.ion.impl.bin._Private_IonRawWriter in project ion-java by amzn.

the class IonRawWriterBasicTest method testRawWriteIVMFails.

@Test
public void testRawWriteIVMFails() throws IOException {
    _Private_IonRawWriter rawWriter = basicRawWriter();
    rawWriter.addTypeAnnotationSymbol(10);
    // Symbol 2 with an annotation is not IVM
    rawWriter.writeSymbolToken(2);
    rawWriter.stepIn(IonType.STRUCT);
    rawWriter.setFieldNameSymbol(11);
    // Symbol 2 below top level is not IVM
    rawWriter.writeSymbolToken(2);
    rawWriter.stepOut();
    thrown.expect(IonException.class);
    // Top-level symbol 2 is IVM
    rawWriter.writeSymbolToken(2);
}
Also used : com.amazon.ion.impl.bin._Private_IonRawWriter(com.amazon.ion.impl.bin._Private_IonRawWriter) Test(org.junit.Test)

Example 7 with com.amazon.ion.impl.bin._Private_IonRawWriter

use of com.amazon.ion.impl.bin._Private_IonRawWriter in project ion-java by amzn.

the class IonRawWriterBasicTest method testRawSetFieldNameOutsideStructFails.

@Test
public void testRawSetFieldNameOutsideStructFails() {
    _Private_IonRawWriter rawWriter = basicRawWriter();
    thrown.expect(IonException.class);
    rawWriter.setFieldNameSymbol(10);
}
Also used : com.amazon.ion.impl.bin._Private_IonRawWriter(com.amazon.ion.impl.bin._Private_IonRawWriter) Test(org.junit.Test)

Example 8 with com.amazon.ion.impl.bin._Private_IonRawWriter

use of com.amazon.ion.impl.bin._Private_IonRawWriter in project ion-java by amzn.

the class IonReaderBinaryIncrementalTest method multipleSymbolTablesWithSymbolsThenImports.

@Test
public void multipleSymbolTablesWithSymbolsThenImports() throws Exception {
    SimpleCatalog catalog = new SimpleCatalog();
    catalog.putTable(SYSTEM.newSharedSymbolTable("foo", 1, Arrays.asList("abc", "def").iterator()));
    catalog.putTable(SYSTEM.newSharedSymbolTable("bar", 1, Collections.singletonList("baz").iterator()));
    readerBuilder = IonReaderBuilder.standard().withCatalog(catalog);
    IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {

        @Override
        public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
            SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
            writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
            writer.stepIn(IonType.STRUCT);
            writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
            writer.stepIn(IonType.LIST);
            writer.writeString("ghi");
            writer.stepOut();
            writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
            writer.stepIn(IonType.LIST);
            writer.stepIn(IonType.STRUCT);
            writer.setFieldNameSymbol(systemTable.findSymbol("name"));
            writer.writeString("foo");
            writer.setFieldNameSymbol(systemTable.findSymbol("version"));
            writer.writeInt(1);
            writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
            writer.writeInt(2);
            writer.stepOut();
            writer.stepOut();
            writer.stepOut();
            writer.writeSymbolToken(10);
            writer.writeSymbolToken(11);
            writer.writeSymbolToken(12);
            writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
            writer.stepIn(IonType.STRUCT);
            writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
            writer.stepIn(IonType.LIST);
            writer.writeString("xyz");
            writer.writeString("uvw");
            writer.writeString("rst");
            writer.stepOut();
            writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
            writer.stepIn(IonType.LIST);
            writer.stepIn(IonType.STRUCT);
            writer.setFieldNameSymbol(systemTable.findSymbol("name"));
            writer.writeString("bar");
            writer.setFieldNameSymbol(systemTable.findSymbol("version"));
            writer.writeInt(1);
            writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
            writer.writeInt(1);
            writer.stepOut();
            writer.stepOut();
            writer.stepOut();
            writer.writeSymbolToken(10);
            writer.writeSymbolToken(11);
            writer.writeSymbolToken(12);
            writer.writeSymbolToken(13);
        }
    });
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("abc", reader.stringValue());
    SymbolTable[] imports = reader.getSymbolTable().getImportedTables();
    assertEquals(1, imports.length);
    assertEquals("foo", imports[0].getName());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("def", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("ghi", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("baz", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    imports = reader.getSymbolTable().getImportedTables();
    assertEquals(1, imports.length);
    assertEquals("bar", imports[0].getName());
    assertEquals("xyz", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("uvw", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("rst", reader.stringValue());
    assertNull(reader.next());
    reader.close();
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) com.amazon.ion.impl.bin._Private_IonRawWriter(com.amazon.ion.impl.bin._Private_IonRawWriter) SymbolTable(com.amazon.ion.SymbolTable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with com.amazon.ion.impl.bin._Private_IonRawWriter

use of com.amazon.ion.impl.bin._Private_IonRawWriter in project ion-java by amzn.

the class IonReaderBinaryIncrementalTest method symbolTableWithManySymbolsThenImports.

@Test
public void symbolTableWithManySymbolsThenImports() throws Exception {
    SimpleCatalog catalog = new SimpleCatalog();
    catalog.putTable(SYSTEM.newSharedSymbolTable("foo", 1, Arrays.asList("abc", "def").iterator()));
    readerBuilder = IonReaderBuilder.standard().withCatalog(catalog);
    IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {

        @Override
        public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
            SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
            writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
            writer.stepIn(IonType.STRUCT);
            writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
            writer.stepIn(IonType.LIST);
            writer.writeString("ghi");
            writer.writeString("jkl");
            writer.writeString("mno");
            writer.writeString("pqr");
            writer.stepOut();
            writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
            writer.stepIn(IonType.LIST);
            writer.stepIn(IonType.STRUCT);
            writer.setFieldNameSymbol(systemTable.findSymbol("name"));
            writer.writeString("foo");
            writer.setFieldNameSymbol(systemTable.findSymbol("version"));
            writer.writeInt(1);
            writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
            writer.writeInt(2);
            writer.stepOut();
            writer.stepOut();
            writer.stepOut();
            writer.writeSymbolToken(10);
            writer.writeSymbolToken(11);
            writer.writeSymbolToken(12);
            writer.writeSymbolToken(13);
            writer.writeSymbolToken(14);
            writer.writeSymbolToken(15);
        }
    });
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("abc", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("def", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("ghi", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("jkl", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("mno", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("pqr", reader.stringValue());
    assertNull(reader.next());
    reader.close();
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) com.amazon.ion.impl.bin._Private_IonRawWriter(com.amazon.ion.impl.bin._Private_IonRawWriter) SymbolTable(com.amazon.ion.SymbolTable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with com.amazon.ion.impl.bin._Private_IonRawWriter

use of com.amazon.ion.impl.bin._Private_IonRawWriter in project ion-java by amzn.

the class IonReaderBinaryIncrementalTest method symbolTableWithMultipleImportsCorrectlyAssignsImportLocations.

@Test
public void symbolTableWithMultipleImportsCorrectlyAssignsImportLocations() throws Exception {
    SimpleCatalog catalog = new SimpleCatalog();
    catalog.putTable(SYSTEM.newSharedSymbolTable("foo", 1, Arrays.asList("abc", "def").iterator()));
    catalog.putTable(SYSTEM.newSharedSymbolTable("bar", 1, Arrays.asList("123", "456").iterator()));
    readerBuilder = IonReaderBuilder.standard().withCatalog(catalog);
    IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {

        @Override
        public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
            SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
            writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
            writer.stepIn(IonType.STRUCT);
            writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
            writer.stepIn(IonType.LIST);
            writer.stepIn(IonType.STRUCT);
            writer.setFieldNameSymbol(systemTable.findSymbol("name"));
            writer.writeString("foo");
            writer.setFieldNameSymbol(systemTable.findSymbol("version"));
            writer.writeInt(1);
            writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
            // The matching shared symbol table in the catalog only declares two symbols.
            writer.writeInt(4);
            writer.stepOut();
            writer.stepIn(IonType.STRUCT);
            writer.setFieldNameSymbol(systemTable.findSymbol("name"));
            writer.writeString("bar");
            writer.setFieldNameSymbol(systemTable.findSymbol("version"));
            writer.writeInt(1);
            writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
            // The matching shared symbol table in the catalog declares two symbols, but only one is used.
            writer.writeInt(1);
            writer.stepOut();
            writer.stepIn(IonType.STRUCT);
            writer.setFieldNameSymbol(systemTable.findSymbol("name"));
            // There is no match in the catalog; all symbols have unknown text.
            writer.writeString("baz");
            writer.setFieldNameSymbol(systemTable.findSymbol("version"));
            writer.writeInt(1);
            writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
            writer.writeInt(2);
            writer.stepOut();
            writer.stepOut();
            writer.stepOut();
            // abc
            writer.writeSymbolToken(10);
            // def
            writer.writeSymbolToken(11);
            // unknown text, import SID 3 (from foo)
            writer.writeSymbolToken(12);
            // unknown text, import SID 4 (from foo)
            writer.writeSymbolToken(13);
            // 123
            writer.writeSymbolToken(14);
            // unknown text, import SID 1 (from baz)
            writer.writeSymbolToken(15);
            // unknown text, import SID 2 (from baz)
            writer.writeSymbolToken(16);
        }
    });
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("abc", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("def", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    IonReaderBinaryIncremental.SymbolTokenImpl symbolValue = (IonReaderBinaryIncremental.SymbolTokenImpl) reader.symbolValue();
    assertNull(symbolValue.getText());
    assertEquals(new ImportLocation("foo", 3), symbolValue.getImportLocation());
    assertEquals(IonType.SYMBOL, reader.next());
    symbolValue = (IonReaderBinaryIncremental.SymbolTokenImpl) reader.symbolValue();
    assertNull(symbolValue.getText());
    assertEquals(new ImportLocation("foo", 4), symbolValue.getImportLocation());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("123", reader.stringValue());
    assertEquals(IonType.SYMBOL, reader.next());
    symbolValue = (IonReaderBinaryIncremental.SymbolTokenImpl) reader.symbolValue();
    assertEquals(new IonReaderBinaryIncremental.SymbolTokenImpl(null, 15, new ImportLocation("baz", 1)), symbolValue);
    assertEquals(IonType.SYMBOL, reader.next());
    symbolValue = (IonReaderBinaryIncremental.SymbolTokenImpl) reader.symbolValue();
    assertEquals(new IonReaderBinaryIncremental.SymbolTokenImpl(null, 16, new ImportLocation("baz", 2)), symbolValue);
    assertNull(reader.next());
    reader.close();
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) com.amazon.ion.impl.bin._Private_IonRawWriter(com.amazon.ion.impl.bin._Private_IonRawWriter) SymbolTable(com.amazon.ion.SymbolTable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

com.amazon.ion.impl.bin._Private_IonRawWriter (com.amazon.ion.impl.bin._Private_IonRawWriter)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 Test (org.junit.Test)11 IOException (java.io.IOException)7 SymbolTable (com.amazon.ion.SymbolTable)6 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)5 com.amazon.ion.impl.bin._Private_IonManagedWriter (com.amazon.ion.impl.bin._Private_IonManagedWriter)4 SymbolToken (com.amazon.ion.SymbolToken)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 BigInteger (java.math.BigInteger)1