Search in sources :

Example 66 with IonWriter

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

the class IonBinaryWriterBuilderTest method testImports.

// -------------------------------------------------------------------------
@Test
public void testImports() {
    SymbolTable f = Symtabs.CATALOG.getTable("fred", 1);
    SymbolTable g = Symtabs.CATALOG.getTable("ginger", 1);
    SymbolTable[] symtabsF = new SymbolTable[] { f };
    SymbolTable[] symtabsG = new SymbolTable[] { g };
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
    b.setImports(f);
    OutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    SymbolTable st = writer.getSymbolTable();
    assertArrayEquals(symtabsF, st.getImportedTables());
    // Test with...() on mutable builder
    IonBinaryWriterBuilder b2 = b.withImports(g);
    assertSame(b, b2);
    assertArrayEquals(symtabsG, b2.getImports());
    // Test with...() on immutable builder
    b2 = b.immutable();
    assertArrayEquals(symtabsG, b2.getImports());
    IonBinaryWriterBuilder b3 = b2.withImports(f);
    assertNotSame(b2, b3);
    assertArrayEquals(symtabsG, b2.getImports());
    assertArrayEquals(symtabsF, b3.getImports());
    // Test cloning of array
    SymbolTable[] symtabs = new SymbolTable[] { f };
    b3.setImports(symtabs);
    assertNotSame(symtabs, b3.getImports());
    assertArrayEquals(symtabsF, b3.getImports());
    symtabs[0] = g;
    assertArrayEquals(symtabsF, b3.getImports());
    b3.getImports()[0] = g;
    assertArrayEquals(symtabsF, b3.getImports());
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) SymbolTable(com.amazon.ion.SymbolTable) IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 67 with IonWriter

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

the class IonReaderBuilderTest method testSystemFreeRoundtrip.

@Test
public void testSystemFreeRoundtrip() throws IOException {
    // No IonSystem in sight.
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IonWriter writer = _Private_IonBinaryWriterBuilder.standard().build(out);
    writer.writeInt(42);
    writer.finish();
    IonReader reader = IonReaderBuilder.standard().build(out.toByteArray());
    assertEquals(IonType.INT, reader.next());
    assertEquals(42, reader.intValue());
}
Also used : IonReader(com.amazon.ion.IonReader) IonWriter(com.amazon.ion.IonWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 68 with IonWriter

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

the class IonSystemBuilderTest method testStreamCopyOptimized.

// -------------------------------------------------------------------------
@Test
public void testStreamCopyOptimized() {
    IonSystemBuilder b = IonSystemBuilder.standard().copy();
    b.setStreamCopyOptimized(true);
    IonSystem ion = b.build();
    assertTrue(isLiteSystem(ion));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IonWriter w = ion.newBinaryWriter(out);
    assertTrue(((_Private_IonWriter) w).isStreamCopyOptimized());
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 69 with IonWriter

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

the class IonTextWriterBuilderTest method testCustomCatalog.

// -------------------------------------------------------------------------
@Test
public void testCustomCatalog() {
    IonCatalog catalog = new SimpleCatalog();
    IonTextWriterBuilder b = IonTextWriterBuilder.standard();
    b.setCatalog(catalog);
    assertSame(catalog, b.getCatalog());
    StringBuilder out = new StringBuilder();
    IonWriter writer = b.build(out);
    assertSame(catalog, ((_Private_IonWriter) writer).getCatalog());
    IonCatalog catalog2 = new SimpleCatalog();
    b.setCatalog(catalog2);
    assertSame(catalog2, b.getCatalog());
    // Test with...() on mutable builder
    IonTextWriterBuilder b2 = b.withCatalog(catalog);
    assertSame(b, b2);
    assertSame(catalog, b2.getCatalog());
    // Test with...() on immutable builder
    b2 = b.immutable();
    assertSame(catalog, b2.getCatalog());
    IonTextWriterBuilder b3 = b2.withCatalog(catalog2);
    assertNotSame(b2, b3);
    assertSame(catalog, b2.getCatalog());
    assertSame(catalog2, b3.getCatalog());
}
Also used : IonCatalog(com.amazon.ion.IonCatalog) IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) Test(org.junit.Test)

Example 70 with IonWriter

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

the class IonTextWriterBuilderTest method testStandard.

@Test
public void testStandard() {
    IonTextWriterBuilder b = IonTextWriterBuilder.standard();
    Assert.assertNotNull(b);
    testBuildNull(b);
    StringBuilder out = new StringBuilder();
    IonWriter writer = b.build(out);
    Assert.assertNotNull(writer);
    assertNotSame(b, IonTextWriterBuilder.standard());
}
Also used : IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) Test(org.junit.Test)

Aggregations

IonWriter (com.amazon.ion.IonWriter)71 Test (org.junit.Test)47 ByteArrayOutputStream (java.io.ByteArrayOutputStream)35 IonReader (com.amazon.ion.IonReader)19 com.amazon.ion.impl._Private_IonWriter (com.amazon.ion.impl._Private_IonWriter)16 SymbolTable (com.amazon.ion.SymbolTable)12 IonDatagram (com.amazon.ion.IonDatagram)11 IOException (java.io.IOException)11 IonTextWriterBuilder (com.amazon.ion.system.IonTextWriterBuilder)10 com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)9 IonSystem (com.amazon.ion.IonSystem)8 OutputStream (java.io.OutputStream)8 IonCatalog (com.amazon.ion.IonCatalog)4 IonReaderBuilder (com.amazon.ion.system.IonReaderBuilder)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 IonException (com.amazon.ion.IonException)3 IonStruct (com.amazon.ion.IonStruct)3 StringWriter (java.io.StringWriter)3