Search in sources :

Example 61 with IonWriter

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

the class MiscStreamingTest method testTextWriterSymtabs.

@Test
public void testTextWriterSymtabs() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IonWriter writer = system().newTextWriter(out);
    system().newSymbol("foo").writeTo(writer);
    writer.close();
    assertEquals("foo", utf8(out.toByteArray()));
}
Also used : IonWriter(com.amazon.ion.IonWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test) BinaryTest(com.amazon.ion.BinaryTest)

Example 62 with IonWriter

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

the class IonBinaryWriterBuilderTest method testSetIsFloatBinary32Enabled.

// -------------------------------------------------------------------------
@Test
public void testSetIsFloatBinary32Enabled() throws IOException {
    IonSystem system = IonSystemBuilder.standard().build();
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
    b.setIsFloatBinary32Enabled(true);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    writer.writeFloat(1.0);
    writer.close();
    assertEquals(9, out.size());
    assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
    b.setIsFloatBinary32Enabled(false);
    out = new ByteArrayOutputStream();
    writer = b.build(out);
    writer.writeFloat(1.0);
    writer.close();
    assertEquals(13, out.size());
    assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
}
Also used : IonSystem(com.amazon.ion.IonSystem) 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 63 with IonWriter

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

the class IonBinaryWriterBuilderTest method testWithFloatBinary32Enabled.

@Test
public void testWithFloatBinary32Enabled() throws IOException {
    IonSystem system = IonSystemBuilder.standard().build();
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard().withFloatBinary32Enabled();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    writer.writeFloat(1.0);
    writer.close();
    assertEquals(9, out.size());
    assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
}
Also used : IonSystem(com.amazon.ion.IonSystem) 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 64 with IonWriter

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

the class IonBinaryWriterBuilderTest method testInitialSymtab.

// -------------------------------------------------------------------------
@Test
public void testInitialSymtab() throws IOException {
    SymbolTable sst = _Private_Utils.systemSymtab(1);
    SymbolTable lst0 = Symtabs.localSymbolTableFactory().newLocalSymtab(sst);
    lst0.intern("hello");
    _Private_IonBinaryWriterBuilder b = _Private_IonBinaryWriterBuilder.standard();
    b.setInitialSymbolTable(lst0);
    assertSame(lst0, b.getInitialSymbolTable());
    OutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    assertEquals(sst.getMaxId() + 1, writer.getSymbolTable().findSymbol("hello"));
    // Builder makes a copy of the symtab
    SymbolTable lst1 = writer.getSymbolTable();
    assertNotSame(lst0, lst1);
    assertSame(lst0, b.getInitialSymbolTable());
    // Second call to build, we get another copy.
    writer = b.build(out);
    SymbolTable lst2 = writer.getSymbolTable();
    assertNotSame(lst0, lst2);
    assertNotSame(lst1, lst2);
    writer.writeSymbol("addition");
    // Now the LST has been extended, so the builder should make a copy
    // with the original max_id.
    writer = b.build(out);
    SymbolTable lst3 = writer.getSymbolTable();
    assertEquals(sst.getMaxId() + 1, lst3.findSymbol("hello"));
    assertEquals(sst.getMaxId() + 1, lst3.getMaxId());
    assertNotSame(lst0, lst3);
    assertNotSame(lst1, lst3);
    assertNotSame(lst2, lst3);
    assertSame(lst0, b.getInitialSymbolTable());
}
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 65 with IonWriter

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

the class IonBinaryWriterBuilderTest method testWithFloatBinary32Disabled.

@Test
public void testWithFloatBinary32Disabled() throws IOException {
    IonSystem system = IonSystemBuilder.standard().build();
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard().withFloatBinary32Disabled();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    writer.writeFloat(1.0);
    writer.close();
    assertEquals(13, out.size());
    assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
}
Also used : IonSystem(com.amazon.ion.IonSystem) 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