use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonWriterSystemText method writeAnnotations.
void writeAnnotations(SymbolToken[] annotations) throws IOException {
for (SymbolToken ann : annotations) {
writeAnnotationToken(ann);
_output.appendAscii("::");
}
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonWriterSystemTree method append.
private void append(IonValue value) {
try {
super.startValue();
} catch (IOException e) {
// Shouldn't happen
throw new IonException(e);
}
if (hasAnnotations()) {
SymbolToken[] annotations = getTypeAnnotationSymbols();
// TODO this makes an extra copy of the array
((_Private_IonValue) value).setTypeAnnotationSymbols(annotations);
this.clearAnnotations();
}
if (_in_struct) {
SymbolToken sym = assumeFieldNameSymbol();
IonStruct struct = (IonStruct) _current_parent;
struct.add(sym, value);
this.clearFieldName();
} else {
((IonSequence) _current_parent).add(value);
}
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class LocalSymbolTable method readLocalSymbolTable.
/**
* Parses the symbol table at the reader's current position.
* @param reader the reader from which to parse the symbol table.
* @param catalog the catalog from which to resolve shared symbol table imports.
* @param isOnStruct true if the reader is already positioned on the symbol table struct; otherwise, false.
* @param symbolsListOut list into which local symbols declared by the parsed symbol table will be deposited.
* @param currentSymbolTable the symbol table currently active in the stream.
* @return a new LocalSymbolTableImports instance, or null if this was an LST append. If null, `currentSymbolTable`
* continues to be the active symbol table.
*/
protected static LocalSymbolTableImports readLocalSymbolTable(IonReader reader, IonCatalog catalog, boolean isOnStruct, List<String> symbolsListOut, SymbolTable currentSymbolTable) {
if (!isOnStruct) {
reader.next();
}
assert reader.getType() == IonType.STRUCT : "invalid symbol table image passed in reader " + reader.getType() + " encountered when a struct was expected";
assert ION_SYMBOL_TABLE.equals(reader.getTypeAnnotations()[0]) : "local symbol tables must be annotated by " + ION_SYMBOL_TABLE;
reader.stepIn();
List<SymbolTable> importsList = new ArrayList<SymbolTable>();
importsList.add(reader.getSymbolTable().getSystemSymbolTable());
IonType fieldType;
boolean foundImportList = false;
boolean foundLocalSymbolList = false;
boolean isAppend = false;
while ((fieldType = reader.next()) != null) {
if (reader.isNullValue())
continue;
SymbolToken symTok = reader.getFieldNameSymbol();
int sid = symTok.getSid();
if (sid == SymbolTable.UNKNOWN_SYMBOL_ID) {
// This is a user-defined IonReader or a pure DOM, fall
// back to text
final String fieldName = reader.getFieldName();
sid = getSidForSymbolTableField(fieldName);
}
// different SID!
switch(sid) {
case SYMBOLS_SID:
{
// empty lists
if (foundLocalSymbolList) {
throw new IonException("Multiple symbol fields found within a single local symbol table.");
}
foundLocalSymbolList = true;
if (fieldType == IonType.LIST) {
reader.stepIn();
IonType type;
while ((type = reader.next()) != null) {
final String text;
if (type == IonType.STRING) {
text = reader.stringValue();
} else {
text = null;
}
symbolsListOut.add(text);
}
reader.stepOut();
}
break;
}
case IMPORTS_SID:
{
if (foundImportList) {
throw new IonException("Multiple imports fields found within a single local symbol table.");
}
foundImportList = true;
if (fieldType == IonType.LIST) {
prepImportsList(importsList, reader, catalog);
} else if (fieldType == IonType.SYMBOL && ION_SYMBOL_TABLE.equals(reader.stringValue())) {
isAppend = true;
}
break;
}
default:
{
// As per the Spec, any other field is ignored
break;
}
}
}
reader.stepOut();
if (isAppend && currentSymbolTable.isLocalTable()) {
// Because the current symbol table is a local symbol table (i.e. not the system symbol table), it can
// be appended in-place.
LocalSymbolTable currentLocalSymbolTable = (LocalSymbolTable) currentSymbolTable;
for (String newSymbol : symbolsListOut) {
currentLocalSymbolTable.putSymbol(newSymbol);
}
return null;
}
return new LocalSymbolTableImports(importsList);
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class LocalSymbolTable method intern.
public synchronized SymbolToken intern(String text) {
SymbolToken is = find(text);
if (is == null) {
validateSymbol(text);
int sid = putSymbol(text);
is = new SymbolTokenImpl(text, sid);
}
return is;
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class LocalSymbolTable method find.
public SymbolToken find(String text) {
// fast null check
text.getClass();
// Look in system then imports
SymbolToken symTok = myImportsList.find(text);
// Look in local symbols
if (symTok == null) {
Integer sid;
String[] names;
synchronized (this) {
sid = mySymbolsMap.get(text);
names = mySymbolNames;
}
if (sid != null) {
int offset = sid - myFirstLocalSid;
String internedText = names[offset];
assert internedText != null;
symTok = new SymbolTokenImpl(internedText, sid);
}
}
return symTok;
}
Aggregations