use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonBinaryWriterBuilderTest method testImportsNull.
@Test
public void testImportsNull() {
SymbolTable f = Symtabs.CATALOG.getTable("fred", 1);
SymbolTable[] symtabs = new SymbolTable[] { f };
IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
b.setImports(symtabs);
b.setImports((SymbolTable[]) null);
assertSame(null, b.getImports());
b.setImports(new SymbolTable[0]);
assertArrayEquals(new SymbolTable[0], b.getImports());
}
use of com.amazon.ion.SymbolTable in project ion-hive-serde by amzn.
the class CatalogConfig method catalogFromReader.
private static IonCatalog catalogFromReader(final IonReader reader) {
final SimpleCatalog catalog = new SimpleCatalog();
while (reader.next() != null) {
@SuppressWarnings("deprecated") final SymbolTable symbolTable = _Private_Utils.newSharedSymtab(reader, true);
catalog.putTable(symbolTable);
}
return catalog;
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonJavaCli method handleSymbolTableEvent.
//
//
// helper functions
//
//
private static void handleSymbolTableEvent(ProcessContext processContext, Event event, CommandArgs args, boolean isEmbedded) throws IOException {
processContext.getIonWriter().close();
ImportDescriptor[] imports = event.getImports();
SymbolTable[] symbolTables = new SymbolTable[imports.length];
for (int i = 0; i < imports.length; i++) {
SymbolTable symbolTable = ION_SYSTEM.newSharedSymbolTable(imports[i].getImportName(), imports[i].getVersion(), null);
symbolTables[i] = symbolTable;
}
if (!isEmbedded) {
OutputStream out = args.getOutputFile() == null ? new NoCloseOutputStream(System.out) : new FileOutputStream(processContext.getFile(), true);
processContext.setIonWriter(args.getOutputFormat().createIonWriterWithImports(out, symbolTables));
} else {
processContext.getEmbeddedOut().append(" ");
processContext.setIonWriter(ION_TEXT_WRITER_BUILDER.withImports(symbolTables).build(processContext.getEmbeddedOut()));
}
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonIteratorImpl method readValue.
private IonValue readValue() {
IonType type = _reader.getType();
SymbolToken[] annotations = _reader.getTypeAnnotationSymbols();
IonValue v;
if (_reader.isNullValue()) {
v = _valueFactory.newNull(type);
} else {
switch(type) {
case NULL:
// Handled above
throw new IllegalStateException();
case BOOL:
v = _valueFactory.newBool(_reader.booleanValue());
break;
case INT:
v = _valueFactory.newInt(_reader.bigIntegerValue());
break;
case FLOAT:
v = _valueFactory.newFloat(_reader.doubleValue());
break;
case DECIMAL:
v = _valueFactory.newDecimal(_reader.decimalValue());
break;
case TIMESTAMP:
v = _valueFactory.newTimestamp(_reader.timestampValue());
break;
case STRING:
v = _valueFactory.newString(_reader.stringValue());
break;
case SYMBOL:
// TODO always pass the SID? Is it correct?
v = _valueFactory.newSymbol(_reader.symbolValue());
break;
case BLOB:
{
IonLob lob = _valueFactory.newNullBlob();
lob.setBytes(_reader.newBytes());
v = lob;
break;
}
case CLOB:
{
IonLob lob = _valueFactory.newNullClob();
lob.setBytes(_reader.newBytes());
v = lob;
break;
}
case STRUCT:
{
IonStruct struct = _valueFactory.newEmptyStruct();
_reader.stepIn();
while (_reader.next() != null) {
SymbolToken name = _reader.getFieldNameSymbol();
IonValue child = readValue();
struct.add(name, child);
}
_reader.stepOut();
v = struct;
break;
}
case LIST:
{
IonSequence seq = _valueFactory.newEmptyList();
_reader.stepIn();
while (_reader.next() != null) {
IonValue child = readValue();
seq.add(child);
}
_reader.stepOut();
v = seq;
break;
}
case SEXP:
{
IonSequence seq = _valueFactory.newEmptySexp();
_reader.stepIn();
while (_reader.next() != null) {
IonValue child = readValue();
seq.add(child);
}
_reader.stepOut();
v = seq;
break;
}
default:
throw new IllegalStateException();
}
}
// TODO this is too late in the case of system reading
// when v is a local symtab (it will get itself, not the prior symtab)
SymbolTable symtab = _reader.getSymbolTable();
((_Private_IonValue) v).setSymbolTable(symtab);
if (annotations.length != 0) {
((_Private_IonValue) v).setTypeAnnotationSymbols(annotations);
}
return v;
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonReaderBinarySystemX method getTypeAnnotationSymbols.
public SymbolToken[] getTypeAnnotationSymbols() {
load_annotations();
int count = _annotation_count;
if (count == 0)
return SymbolToken.EMPTY_ARRAY;
SymbolTable symtab = getSymbolTable();
SymbolToken[] result = new SymbolToken[count];
for (int i = 0; i < count; i++) {
int sid = _annotation_ids[i];
String text = symtab.findKnownSymbol(sid);
result[i] = new SymbolTokenImpl(text, sid);
}
return result;
}
Aggregations