Search in sources :

Example 86 with SymbolTable

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

the class IonReaderTreeUserX method pop_passed_symbol_table.

public SymbolTable pop_passed_symbol_table() {
    if (_symbol_table_top <= 0) {
        return null;
    }
    _symbol_table_top--;
    SymbolTable symbols = _symbol_table_stack[_symbol_table_top];
    _symbol_table_stack[_symbol_table_top] = null;
    return symbols;
}
Also used : SymbolTable(com.amazon.ion.SymbolTable)

Example 87 with SymbolTable

use of com.amazon.ion.SymbolTable 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 88 with SymbolTable

use of com.amazon.ion.SymbolTable 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 89 with SymbolTable

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

the class EncodeApp method processOptions.

// =========================================================================
/**
 * @param args
 * @return the next index to process
 */
@Override
protected int processOptions(String[] args) {
    ArrayList<SymbolTable> imports = new ArrayList<SymbolTable>();
    int i;
    for (i = 0; i < args.length; i++) {
        String arg = args[i];
        if ("--catalog".equals(arg)) {
            String symtabPath = args[++i];
            loadCatalog(symtabPath);
        } else if ("--import".equals(arg)) {
            // We'll use the latest version available.
            String name = args[++i];
            SymbolTable symtab = getLatestSharedSymtab(name);
            imports.add(symtab);
        } else if ("--output-dir".equals(arg)) {
            String path = args[++i];
            myOutputDir = new File(path);
            if (!myOutputDir.isDirectory() || !myOutputDir.canWrite()) {
                throw new RuntimeException("Not a writeable directory: " + path);
            }
        } else if ("--output".equals(arg)) {
            String path = args[++i];
            myOutputFile = path;
            myOutputDir = new File(path).getParentFile();
            if (!myOutputDir.isDirectory() || !myOutputDir.canWrite()) {
                throw new RuntimeException("Not a writeable directory: " + path);
            }
        } else {
            // this arg is not an option, we're done here
            break;
        }
    }
    myImports = imports.toArray(new SymbolTable[0]);
    return i;
}
Also used : ArrayList(java.util.ArrayList) SymbolTable(com.amazon.ion.SymbolTable) File(java.io.File)

Example 90 with SymbolTable

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

the class SymtabApp method processFiles.

@Override
public void processFiles(String[] filePaths) {
    super.processFiles(filePaths);
    SymbolTable[] importArray = new SymbolTable[myImports.size()];
    myImports.toArray(importArray);
    SymbolTable mySymtab = mySystem.newSharedSymbolTable(mySymtabName, mySymtabVersion, mySymbols.iterator(), importArray);
    IonWriter w = mySystem.newTextWriter((OutputStream) System.out);
    try {
        // TODO ensure IVM is printed
        mySymtab.writeTo(w);
        System.out.println();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) IonWriter(com.amazon.ion.IonWriter) IOException(java.io.IOException)

Aggregations

SymbolTable (com.amazon.ion.SymbolTable)177 Test (org.junit.Test)105 IonValue (com.amazon.ion.IonValue)21 IonDatagram (com.amazon.ion.IonDatagram)18 com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable (com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable)17 SymbolToken (com.amazon.ion.SymbolToken)14 IonStruct (com.amazon.ion.IonStruct)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 IonWriter (com.amazon.ion.IonWriter)12 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)12 IonReader (com.amazon.ion.IonReader)11 IonSystem (com.amazon.ion.IonSystem)10 IOException (java.io.IOException)9 IonType (com.amazon.ion.IonType)8 ArrayList (java.util.ArrayList)7 IonException (com.amazon.ion.IonException)6 com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)6 com.amazon.ion.impl.bin._Private_IonRawWriter (com.amazon.ion.impl.bin._Private_IonRawWriter)6 IonCatalog (com.amazon.ion.IonCatalog)5 IonList (com.amazon.ion.IonList)5