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;
}
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;
}
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("----");
}
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;
}
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();
}
}
Aggregations