use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class _Private_IonWriterBase method transfer_symbol_tables.
private final void transfer_symbol_tables(_Private_ReaderWriter reader) throws IOException {
SymbolTable reader_symbols = reader.pop_passed_symbol_table();
if (reader_symbols != null) {
clear_system_value_stack();
setSymbolTable(reader_symbols);
while (reader_symbols != null) {
// TODO these symtabs are never popped!
// Why bother pushing them?
push_symbol_table(reader_symbols);
reader_symbols = reader.pop_passed_symbol_table();
}
}
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class SymbolTableStructCache method makeIonRepresentation.
/**
* Create a new IonStruct representation of the symbol table.
* @param factory the {@link ValueFactory} from which to construct the IonStruct.
*/
private void makeIonRepresentation(ValueFactory factory) {
image = factory.newEmptyStruct();
image.addTypeAnnotation(ION_SYMBOL_TABLE);
if (importedTables.length > 0) {
// The system symbol table may be the first import. If it is, skip it.
int i = importedTables[0].isSystemTable() ? 1 : 0;
if (i < importedTables.length) {
IonList importsList = factory.newEmptyList();
while (i < importedTables.length) {
SymbolTable importedTable = importedTables[i];
IonStruct importStruct = factory.newEmptyStruct();
importStruct.add(NAME, factory.newString(importedTable.getName()));
importStruct.add(VERSION, factory.newInt(importedTable.getVersion()));
importStruct.add(MAX_ID, factory.newInt(importedTable.getMaxId()));
importsList.add(importStruct);
i++;
}
image.add(IMPORTS, importsList);
}
}
if (symbolTable.getMaxId() > symbolTable.getImportedMaxId()) {
Iterator<String> localSymbolIterator = symbolTable.iterateDeclaredSymbolNames();
int sid = symbolTable.getImportedMaxId() + 1;
while (localSymbolIterator.hasNext()) {
addSymbol(localSymbolIterator.next(), sid);
sid++;
}
}
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class _Private_IonBinaryWriterBuilder method fillLegacyDefaults.
/**
* Fills all properties and returns an immutable builder.
*/
private _Private_IonBinaryWriterBuilder fillLegacyDefaults() {
// amzn/ion-java/issues/59 Fix this to use the new writer or eliminate it
// Ensure that we don't modify the user's builder.
_Private_IonBinaryWriterBuilder b = copy();
if (b.getSymtabValueFactory() == null) {
IonSystem system = IonSystemBuilder.standard().build();
b.setSymtabValueFactory(system);
}
SymbolTable initialSymtab = b.getInitialSymbolTable();
if (initialSymtab == null) {
initialSymtab = initialSymtab(LocalSymbolTable.DEFAULT_LST_FACTORY, _Private_Utils.systemSymtab(1), b.getImports());
b.setInitialSymbolTable(initialSymtab);
} else if (initialSymtab.isSystemTable()) {
initialSymtab = initialSymtab(LocalSymbolTable.DEFAULT_LST_FACTORY, initialSymtab, b.getImports());
b.setInitialSymbolTable(initialSymtab);
}
return b.immutable();
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class _Private_IonBinaryWriterBuilder method setInitialSymbolTable.
/**
* Declares the symbol table to use for encoded data.
* To avoid conflicts between different data streams, if the given instance
* is mutable, it will be copied when {@code build()} is called.
*
* @param symtab must be a local or system symbol table.
* May be null, in which case the initial symtab is that of
* {@code $ion_1_0}.
*
* @throws SubstituteSymbolTableException
* if any imported table is a substitute (see {@link SymbolTable}).
*/
@Override
public void setInitialSymbolTable(SymbolTable symtab) {
mutationCheck();
if (symtab != null) {
if (symtab.isLocalTable()) {
SymbolTable[] imports = ((LocalSymbolTable) symtab).getImportedTablesNoCopy();
for (SymbolTable imported : imports) {
if (imported.isSubstitute()) {
String message = "Cannot encode with substitute symbol table: " + imported.getName();
throw new SubstituteSymbolTableException(message);
}
}
} else if (!symtab.isSystemTable()) {
String message = "symtab must be local or system table";
throw new IllegalArgumentException(message);
}
}
myInitialSymbolTable = symtab;
myBinaryWriterBuilder.withInitialSymbolTable(symtab);
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonWriterSystemBinary method writeRecursive.
int writeRecursive(BlockedByteInputStream datastream, OutputStream userstream, PatchedValues p) throws IOException {
int totalSize = 0;
for (int i = 0; i <= p._freePos; ++i) {
int type = p._types[i];
int pos = p._positions[i];
int fnlen = (int) (p._lengths[i] >> 32);
int vallen = (int) (p._lengths[i] & 0xFFFFFFFF);
if (p.getParent() == null) {
if (pos > totalSize) {
// write whatever data that we have in the datastream (eg external data)
datastream.writeTo(userstream, pos - totalSize);
totalSize = pos;
}
totalSize += fnlen + vallen;
}
// write member name
if (fnlen > 0) {
datastream.writeTo(userstream, fnlen);
}
switch(type) {
case TID_ANNOTATION_PATCH:
IonBinary.writeVarUInt(userstream, vallen);
datastream.writeTo(userstream, vallen);
break;
case TID_SYMBOL_TABLE_PATCH:
SymbolTable symtab = p._symtabs.remove();
if (!symtab.isSystemTable()) {
byte[] symtabBytes = reverseEncode(1024, symtab);
userstream.write(symtabBytes);
totalSize += symtabBytes.length;
}
break;
case TID_RAW:
datastream.writeTo(userstream, vallen);
break;
default:
// write type
if (vallen >= _Private_IonConstants.lnIsVarLen) {
int typeByte = (type << 4) | _Private_IonConstants.lnIsVarLen;
userstream.write(typeByte);
IonBinary.writeVarUInt(userstream, vallen);
} else {
int typeByte = (type << 4) | vallen;
userstream.write(typeByte);
}
switch(type) {
case _Private_IonConstants.tidList:
case _Private_IonConstants.tidSexp:
case _Private_IonConstants.tidStruct:
case _Private_IonConstants.tidTypedecl:
// write the container
assert p._children != null;
writeRecursive(datastream, userstream, p._children.remove());
break;
default:
datastream.writeTo(userstream, vallen);
}
}
}
return totalSize;
}
Aggregations