Search in sources :

Example 11 with IonException

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;
}
Also used : IonException(com.amazon.ion.IonException) BigInteger(java.math.BigInteger)

Example 12 with IonException

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'"));
    }
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonException(com.amazon.ion.IonException)

Example 13 with IonException

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;
    }
}
Also used : IonException(com.amazon.ion.IonException) IonReader(com.amazon.ion.IonReader) Test(org.junit.Test)

Example 14 with IonException

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;
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonException(com.amazon.ion.IonException)

Example 15 with IonException

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);
    }
}
Also used : IonException(com.amazon.ion.IonException) IOException(java.io.IOException) BufferManager(com.amazon.ion.impl.IonBinary.BufferManager) Test(org.junit.Test)

Aggregations

IonException (com.amazon.ion.IonException)66 IOException (java.io.IOException)31 IonReader (com.amazon.ion.IonReader)10 IonType (com.amazon.ion.IonType)9 SymbolToken (com.amazon.ion.SymbolToken)9 IonValue (com.amazon.ion.IonValue)7 Event (com.amazon.tools.events.Event)7 Test (org.junit.Test)6 IonStruct (com.amazon.ion.IonStruct)5 SymbolTable (com.amazon.ion.SymbolTable)5 SavePoint (com.amazon.ion.impl.UnifiedSavePointManagerX.SavePoint)5 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 EventType (com.amazon.tools.events.EventType)4 IonWriter (com.amazon.ion.IonWriter)3 IonDatagram (com.amazon.ion.IonDatagram)2 IonLob (com.amazon.ion.IonLob)2 Timestamp (com.amazon.ion.Timestamp)2 BufferManager (com.amazon.ion.impl.IonBinary.BufferManager)2 com.amazon.ion.impl._Private_IonWriter (com.amazon.ion.impl._Private_IonWriter)2