use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonManagedBinaryWriter method setFieldName.
// Current Value Meta
public void setFieldName(final String name) {
if (!isInStruct()) {
throw new IllegalStateException("IonWriter.setFieldName() must be called before writing a value into a struct.");
}
if (name == null) {
throw new NullPointerException("Null field name is not allowed.");
}
final SymbolToken token = intern(name);
user.setFieldNameSymbol(token);
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonManagedBinaryWriter method addTypeAnnotation.
public void addTypeAnnotation(final String annotation) {
final SymbolToken token = intern(annotation);
user.addTypeAnnotationSymbol(token);
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonValueLite method addTypeAnnotation.
public /* synchronized */
void addTypeAnnotation(String annotation) {
checkForLock();
if (annotation == null || annotation.length() < 1) {
throw new IllegalArgumentException("a user type annotation must be a non-empty string");
}
// we don't add duplicate annotations
if (hasTypeAnnotation(annotation))
return;
SymbolToken sym = newSymbolToken(annotation, UNKNOWN_SYMBOL_ID);
int old_len = (_annotations == null) ? 0 : _annotations.length;
if (old_len > 0) {
for (int ii = 0; ii < old_len; ii++) {
if (_annotations[ii] == null) {
_annotations[ii] = sym;
return;
}
}
}
int new_len = (old_len == 0) ? 1 : old_len * 2;
SymbolToken[] temp = new SymbolToken[new_len];
if (old_len > 0) {
System.arraycopy(_annotations, 0, temp, 0, old_len);
}
_annotations = temp;
_annotations[old_len] = sym;
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class IonValueLite method removeTypeAnnotation.
public void removeTypeAnnotation(String annotation) {
checkForLock();
if (annotation != null && annotation.length() > 0) {
int pos = findTypeAnnotation(annotation);
if (pos < 0) {
return;
}
int ii;
for (ii = pos; ii < _annotations.length - 1; ii++) {
SymbolToken a = _annotations[ii + 1];
if (a == null) {
break;
}
_annotations[ii] = a;
}
if (ii < _annotations.length) {
_annotations[ii] = null;
}
}
}
use of com.amazon.ion.SymbolToken in project ion-java by amzn.
the class AbstractIonWriter method writeValueRecursive.
public final void writeValueRecursive(final IonReader reader) throws IOException {
final IonType type = reader.getType();
final SymbolToken fieldName = reader.getFieldNameSymbol();
if (fieldName != null && !isFieldNameSet() && isInStruct()) {
setFieldNameSymbol(fieldName);
}
final SymbolToken[] annotations = reader.getTypeAnnotationSymbols();
if (annotations.length > 0) {
setTypeAnnotationSymbols(annotations);
}
if (reader.isNullValue()) {
writeNull(type);
return;
}
switch(type) {
case BOOL:
final boolean booleanValue = reader.booleanValue();
writeBool(booleanValue);
break;
case INT:
switch(reader.getIntegerSize()) {
case INT:
final int intValue = reader.intValue();
writeInt(intValue);
break;
case LONG:
final long longValue = reader.longValue();
writeInt(longValue);
break;
case BIG_INTEGER:
final BigInteger bigIntegerValue = reader.bigIntegerValue();
writeInt(bigIntegerValue);
break;
default:
throw new IllegalStateException();
}
break;
case FLOAT:
final double doubleValue = reader.doubleValue();
writeFloat(doubleValue);
break;
case DECIMAL:
final Decimal decimalValue = reader.decimalValue();
writeDecimal(decimalValue);
break;
case TIMESTAMP:
final Timestamp timestampValue = reader.timestampValue();
writeTimestamp(timestampValue);
break;
case SYMBOL:
final SymbolToken symbolToken = reader.symbolValue();
writeSymbolToken(symbolToken);
break;
case STRING:
final String stringValue = reader.stringValue();
writeString(stringValue);
break;
case CLOB:
final byte[] clobValue = reader.newBytes();
writeClob(clobValue);
break;
case BLOB:
final byte[] blobValue = reader.newBytes();
writeBlob(blobValue);
break;
case LIST:
case SEXP:
case STRUCT:
reader.stepIn();
stepIn(type);
while (reader.next() != null) {
writeValue(reader);
}
stepOut();
reader.stepOut();
break;
default:
throw new IllegalStateException("Unexpected type: " + type);
}
}
Aggregations