Search in sources :

Example 1 with IonCatalog

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

the class _Private_IonTextWriterBuilder method build.

/**
 * Assumes that {@link #fillDefaults()} has been called.
 */
private IonWriter build(_Private_FastAppendable appender) {
    IonCatalog catalog = getCatalog();
    SymbolTable[] imports = getImports();
    // TODO We shouldn't need a system here
    IonSystem system = IonSystemBuilder.standard().withCatalog(catalog).build();
    SymbolTable defaultSystemSymtab = system.getSystemSymbolTable();
    IonWriterSystemText systemWriter = (getCallbackBuilder() == null ? new IonWriterSystemText(defaultSystemSymtab, this, appender) : new IonWriterSystemTextMarkup(defaultSystemSymtab, this, appender));
    SymbolTable initialSymtab = initialSymtab(((_Private_ValueFactory) system).getLstFactory(), defaultSystemSymtab, imports);
    return new IonWriterUser(catalog, system, systemWriter, initialSymtab);
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonCatalog(com.amazon.ion.IonCatalog) SymbolTable(com.amazon.ion.SymbolTable)

Example 2 with IonCatalog

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

the class _Private_IonWriterFactory method makeSystemWriter.

/**
 * @param container must not be null.
 */
public static IonWriter makeSystemWriter(IonContainer container) {
    IonSystem sys = container.getSystem();
    IonCatalog cat = sys.getCatalog();
    SymbolTable defaultSystemSymtab = sys.getSystemSymbolTable();
    IonWriter writer = new IonWriterSystemTree(defaultSystemSymtab, cat, container, null);
    return writer;
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonCatalog(com.amazon.ion.IonCatalog) SymbolTable(com.amazon.ion.SymbolTable) IonWriter(com.amazon.ion.IonWriter)

Example 3 with IonCatalog

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

the class IonSystemBuilderTest method testCopy.

@Test
public void testCopy() {
    IonCatalog catalog = new SimpleCatalog();
    IonSystemBuilder b1 = IonSystemBuilder.standard().withCatalog(catalog).withStreamCopyOptimized(true);
    IonSystemBuilder b2 = b1.copy();
    assertNotSame(b1, b2);
    assertSame(b1.getCatalog(), b2.getCatalog());
    assertSame(b1.isStreamCopyOptimized(), b2.isStreamCopyOptimized());
}
Also used : IonCatalog(com.amazon.ion.IonCatalog) Test(org.junit.Test)

Example 4 with IonCatalog

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

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

the class IonBinaryWriterBuilderTest method testCatalogImmutability.

@Test(expected = UnsupportedOperationException.class)
public void testCatalogImmutability() {
    IonCatalog catalog = new SimpleCatalog();
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
    b.setCatalog(catalog);
    IonBinaryWriterBuilder b2 = b.immutable();
    assertSame(catalog, b2.getCatalog());
    b2.setCatalog(null);
}
Also used : IonCatalog(com.amazon.ion.IonCatalog) com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) Test(org.junit.Test)

Aggregations

IonCatalog (com.amazon.ion.IonCatalog)19 Test (org.junit.Test)12 IonSystem (com.amazon.ion.IonSystem)5 SymbolTable (com.amazon.ion.SymbolTable)5 IonWriter (com.amazon.ion.IonWriter)4 com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)3 com.amazon.ion.impl._Private_IonWriter (com.amazon.ion.impl._Private_IonWriter)2 IonDatagram (com.amazon.ion.IonDatagram)1 IonException (com.amazon.ion.IonException)1 IonReader (com.amazon.ion.IonReader)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1