Search in sources :

Example 31 with IonWriter

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

the class IonTextWriterBuilderTest method testIvmMinimization.

@Test
public void testIvmMinimization() throws IOException {
    IonTextWriterBuilder b = IonTextWriterBuilder.standard();
    StringBuilder out = new StringBuilder();
    IonWriter writer = b.build(out);
    writer.writeSymbol(ION_1_0);
    writer.writeSymbol(ION_1_0);
    writer.close();
    assertEquals(ION_1_0 + " " + ION_1_0, out.toString());
    b.withIvmMinimizing(ADJACENT);
    out.setLength(0);
    writer = b.build(out);
    writer.writeSymbol(ION_1_0);
    writer.writeSymbol(ION_1_0);
    writer.writeNull();
    writer.writeSymbol(ION_1_0);
    writer.writeSymbol(ION_1_0);
    writer.close();
    assertEquals(ION_1_0 + " null " + ION_1_0, out.toString());
    b.withIvmMinimizing(DISTANT);
    out.setLength(0);
    writer = b.build(out);
    writer.writeSymbol(ION_1_0);
    writer.writeSymbol(ION_1_0);
    writer.writeNull();
    writer.writeSymbol(ION_1_0);
    writer.writeSymbol(ION_1_0);
    writer.close();
    assertEquals(ION_1_0 + " null", out.toString());
}
Also used : IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) Test(org.junit.Test)

Example 32 with IonWriter

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

the class IonBinaryWriterBuilderTest method testCustomCatalog.

// -------------------------------------------------------------------------
@Test
public void testCustomCatalog() {
    IonCatalog catalog = new SimpleCatalog();
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
    b.setCatalog(catalog);
    assertSame(catalog, b.getCatalog());
    OutputStream out = new ByteArrayOutputStream();
    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
    IonBinaryWriterBuilder b2 = b.withCatalog(catalog);
    assertSame(b, b2);
    assertSame(catalog, b2.getCatalog());
    // Test with...() on immutable builder
    b2 = b.immutable();
    assertSame(catalog, b2.getCatalog());
    IonBinaryWriterBuilder b3 = b2.withCatalog(catalog2);
    assertNotSame(b2, b3);
    assertSame(catalog, b2.getCatalog());
    assertSame(catalog2, b3.getCatalog());
}
Also used : IonCatalog(com.amazon.ion.IonCatalog) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) 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 33 with IonWriter

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

the class IonBinaryWriterBuilderTest method testImmutableInitialSymtab.

@Test
public void testImmutableInitialSymtab() {
    SymbolTable sst = _Private_Utils.systemSymtab(1);
    // Immutable local symtabs shouldn't get copied.
    SymbolTable lst = Symtabs.localSymbolTableFactory().newLocalSymtab(sst);
    lst.intern("hello");
    lst.makeReadOnly();
    _Private_IonBinaryWriterBuilder b = _Private_IonBinaryWriterBuilder.standard();
    b.setInitialSymbolTable(lst);
    assertSame(lst, b.getInitialSymbolTable());
    OutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    assertTrue(symbolTableEquals(lst, writer.getSymbolTable()));
    writer = b.build(out);
    assertTrue(symbolTableEquals(lst, writer.getSymbolTable()));
}
Also used : com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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 34 with IonWriter

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

the class IonBinaryWriterBuilderTest method testStandard.

@Test
public void testStandard() {
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
    Assert.assertNotNull(b);
    testBuildNull(b);
    OutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    Assert.assertNotNull(writer);
    assertNotSame(b, IonBinaryWriterBuilder.standard());
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) 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 35 with IonWriter

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

the class IonBinaryWriterBuilderTest method testStreamCopyOptimized.

// -------------------------------------------------------------------------
@Test
public void testStreamCopyOptimized() {
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
    b.setStreamCopyOptimized(true);
    assertTrue(b.isStreamCopyOptimized());
    OutputStream out = new ByteArrayOutputStream();
    IonWriter w = b.build(out);
    assertTrue(((_Private_IonWriter) w).isStreamCopyOptimized());
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) 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)

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