Search in sources :

Example 6 with IonCatalog

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

the class IonReaderBuilderTest method testImmutable.

@Test
public void testImmutable() {
    IonCatalog catalog = new SimpleCatalog();
    IonReaderBuilder mutable = IonReaderBuilder.standard().withCatalog(catalog);
    IonReaderBuilder immutable = mutable.immutable();
    mutable.withCatalog(new SimpleCatalog());
    assertNotSame(catalog, mutable.getCatalog());
    assertSame(catalog, immutable.getCatalog());
}
Also used : IonCatalog(com.amazon.ion.IonCatalog) Test(org.junit.Test)

Example 7 with IonCatalog

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

the class IonReaderBuilderTest method testMutateCopiedImmutable.

@Test
public void testMutateCopiedImmutable() {
    IonCatalog catalog = new SimpleCatalog();
    IonReaderBuilder immutable = IonReaderBuilder.standard().withCatalog(catalog).immutable();
    IonReaderBuilder mutableCopy = immutable.copy();
    assertSame(immutable, immutable.immutable());
    assertNotSame(immutable, mutableCopy);
    assertSame(catalog, mutableCopy.getCatalog());
    mutableCopy.withCatalog(new SimpleCatalog());
    assertNotSame(catalog, mutableCopy.getCatalog());
}
Also used : IonCatalog(com.amazon.ion.IonCatalog) Test(org.junit.Test)

Example 8 with IonCatalog

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

the class BaseApp method getLatestSharedSymtab.

protected SymbolTable getLatestSharedSymtab(String name) {
    IonCatalog catalog = mySystem.getCatalog();
    SymbolTable table = catalog.getTable(name);
    if (table == null) {
        String message = "There's no symbol table in the catalog named " + name;
        throw new RuntimeException(message);
    }
    logDebug("Found shared symbol table " + name + "@" + table.getVersion());
    return table;
}
Also used : IonCatalog(com.amazon.ion.IonCatalog) SymbolTable(com.amazon.ion.SymbolTable)

Example 9 with IonCatalog

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

the class BaseApp method loadCatalog.

protected void loadCatalog(String catalogPath) {
    System.err.println("Loading catalog from " + catalogPath);
    File catalogFile = new File(catalogPath);
    try {
        InputStream in = new BufferedInputStream(new FileInputStream(catalogFile));
        try {
            IonReader reader = mySystem.newReader(in);
            while (reader.next() != null) {
                SymbolTable symtab = mySystem.newSharedSymbolTable(reader, true);
                myCatalog.putTable(symtab);
            }
        } finally {
            in.close();
        }
    } catch (Exception e) {
        throw new RuntimeException("Error loading catalog from " + catalogPath + ": " + e.getMessage(), e);
    }
    IonCatalog catalog = mySystem.getCatalog();
    assert myCatalog == catalog;
// logDebug("----Catalog content:");
// for (Iterator<StaticSymbolTable> i = catalog.iterator(); i.hasNext(); )
// {
// StaticSymbolTable table = i.next();
// logDebug(table.getName() + "@" + table.getVersion());
// }
// logDebug("----");
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IonReader(com.amazon.ion.IonReader) IonCatalog(com.amazon.ion.IonCatalog) SymbolTable(com.amazon.ion.SymbolTable) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) IonException(com.amazon.ion.IonException) FileNotFoundException(java.io.FileNotFoundException)

Example 10 with IonCatalog

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

the class _Private_IonWriterFactory method makeWriter.

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

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