Search in sources :

Example 1 with com.amazon.ion.impl._Private_IonWriter

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

the class IonValueLite method writeTo.

final void writeTo(IonWriter writer, SymbolTableProvider symbolTableProvider) {
    if (writer.isInStruct() && !((_Private_IonWriter) writer).isFieldNameSet()) {
        SymbolToken tok = getFieldNameSymbol(symbolTableProvider);
        if (tok == null) {
            throw new IllegalStateException("Field name not set");
        }
        writer.setFieldNameSymbol(tok);
    }
    SymbolToken[] annotations = getTypeAnnotationSymbols(symbolTableProvider);
    writer.setTypeAnnotationSymbols(annotations);
    try {
        writeBodyTo(writer, symbolTableProvider);
    } catch (IOException e) {
        throw new IonException(e);
    }
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) com.amazon.ion.impl._Private_Utils.newSymbolToken(com.amazon.ion.impl._Private_Utils.newSymbolToken) IonException(com.amazon.ion.IonException) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) IOException(java.io.IOException)

Example 2 with com.amazon.ion.impl._Private_IonWriter

use of com.amazon.ion.impl._Private_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 3 with com.amazon.ion.impl._Private_IonWriter

use of com.amazon.ion.impl._Private_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)

Example 4 with com.amazon.ion.impl._Private_IonWriter

use of com.amazon.ion.impl._Private_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 5 with com.amazon.ion.impl._Private_IonWriter

use of com.amazon.ion.impl._Private_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)

Aggregations

com.amazon.ion.impl._Private_IonWriter (com.amazon.ion.impl._Private_IonWriter)5 IonWriter (com.amazon.ion.IonWriter)4 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IonCatalog (com.amazon.ion.IonCatalog)2 com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)2 OutputStream (java.io.OutputStream)2 IonException (com.amazon.ion.IonException)1 IonSystem (com.amazon.ion.IonSystem)1 SymbolToken (com.amazon.ion.SymbolToken)1 com.amazon.ion.impl._Private_Utils.newSymbolToken (com.amazon.ion.impl._Private_Utils.newSymbolToken)1 IOException (java.io.IOException)1