use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonReaderBinaryIncremental method bigIntegerValue.
@Override
public BigInteger bigIntegerValue() {
BigInteger value;
if (valueType == IonType.INT) {
if (isNullValue()) {
// case).
return null;
}
if (valueTypeID.length == 0) {
return BigInteger.ZERO;
}
value = readUIntAsBigInteger(valueTypeID.isNegativeInt);
if (valueTypeID.isNegativeInt && value.signum() == 0) {
throw new IonException("Int zero may not be negative.");
}
} else if (valueType == IonType.FLOAT) {
if (isNullValue()) {
value = null;
} else {
scalarConverter.addValue(doubleValue());
scalarConverter.setAuthoritativeType(_Private_ScalarConversions.AS_TYPE.double_value);
scalarConverter.cast(scalarConverter.get_conversion_fnid(_Private_ScalarConversions.AS_TYPE.bigInteger_value));
value = scalarConverter.getBigInteger();
scalarConverter.clear();
}
} else if (valueType == IonType.DECIMAL) {
if (isNullValue()) {
value = null;
} else {
scalarConverter.addValue(decimalValue());
scalarConverter.setAuthoritativeType(_Private_ScalarConversions.AS_TYPE.decimal_value);
scalarConverter.cast(scalarConverter.get_conversion_fnid(_Private_ScalarConversions.AS_TYPE.bigInteger_value));
value = scalarConverter.getBigInteger();
scalarConverter.clear();
}
} else {
throw new IllegalStateException("longValue() may only be called on values of type int, float, or decimal.");
}
return value;
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class SharedSymbolTableTest method testMalformedName.
public void testMalformedName(String nameValue) {
IonStruct s = sharedSymtabStruct(system(), "dummy", 1, "x");
putParsedValue(s, SystemSymbols.NAME, nameValue);
try {
myMaker.newSharedSymtab(system(), s);
fail("Expected exception");
} catch (IonException e) {
assertTrue(e.getMessage().contains("'name'"));
}
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class BadIonStreamingTest method testReadingScalars.
@Test(expected = IonException.class)
public void testReadingScalars() throws Exception {
try {
byte[] buf = _Private_Utils.loadFileBytes(myTestFile);
IonReader it = getStreamingMode().newIonReader(system().getCatalog(), buf);
TestUtils.deepRead(it, true);
it.close();
} catch (IonException e) {
/* good - we're expecting an error, there are testing bad input */
if (_debug_output_errors) {
System.out.print(this.myTestFile.getName());
System.out.print(": ");
System.out.println(e.getMessage());
}
throw e;
}
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class IonWriterTestCase method reload.
/**
* Extracts bytes from the current writer and loads it into a datagram.
*/
@SuppressWarnings("unused")
protected IonDatagram reload() throws Exception {
byte[] bytes = outputByteArray();
IonDatagram dg;
if (// Edit for debugging
false) {
try {
// force all the classes to load to we can step
// into the next time we try this and actually
// see what's going on
dg = loader().load(bytes);
} catch (IonException e) {
// do nothing
}
}
dg = loader().load(bytes);
return dg;
}
use of com.amazon.ion.IonException in project ion-java by amzn.
the class ByteBufferTest method testLargeInsertion.
@Test
public void testLargeInsertion() {
BufferManager buf = new BufferManager();
IonBinary.Writer writer = buf.openWriter();
// Write enough data to overflow the first block
byte[] initialData = new byte[BlockedBuffer._defaultBlockSizeMin + 5];
// Now insert lots of stuff at the beginning
try {
writer.write(initialData, 0, initialData.length);
writer.setPosition(0);
writer.insert(5000);
} catch (IOException e) {
throw new IonException(e);
}
}
Aggregations