Search in sources :

Example 61 with IonException

use of com.amazon.ion.IonException in project ion-java by amzn.

the class IonManagedBinaryWriter method intern.

private SymbolToken intern(final String text) {
    if (text == null) {
        return null;
    }
    try {
        SymbolToken token = imports.importedSymbols.get(text);
        if (token != null) {
            if (token.getSid() > ION_1_0_MAX_ID) {
                // using a symbol from an import triggers emitting locals
                startLocalSymbolTableIfNeeded(/*writeIVM*/
                true);
            }
            return token;
        }
        // try the locals
        token = locals.get(text);
        if (token == null) {
            if (localsLocked) {
                throw new IonException("Local symbol table was locked (made read-only)");
            }
            // if we got here, this is a new symbol and we better start up the locals
            startLocalSymbolTableIfNeeded(/*writeIVM*/
            true);
            startLocalSymbolTableSymbolListIfNeeded();
            token = symbol(text, imports.localSidStart + locals.size());
            locals.put(text, token);
            symbols.writeString(text);
        }
        return token;
    } catch (final IOException e) {
        throw new IonException("Error synthesizing symbols", e);
    }
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) IonException(com.amazon.ion.IonException) IOException(java.io.IOException)

Example 62 with IonException

use of com.amazon.ion.IonException in project ion-java by amzn.

the class IonSystemLite method newSharedSymbolTable.

public SymbolTable newSharedSymbolTable(String name, int version, Iterator<String> newSymbols, SymbolTable... imports) {
    // TODO streamline to avoid making this collection
    ArrayList<String> syms = new ArrayList<String>();
    SymbolTable prior = null;
    if (version > 1) {
        int priorVersion = version - 1;
        prior = _catalog.getTable(name, priorVersion);
        if (prior == null || prior.getVersion() != priorVersion) {
            String message = "Catalog does not contain symbol table " + printString(name) + " version " + priorVersion + " required to create version " + version;
            throw new IonException(message);
        }
    }
    for (SymbolTable imported : imports) {
        addAllNonNull(syms, imported.iterateDeclaredSymbolNames());
    }
    addAllNonNull(syms, newSymbols);
    SymbolTable st = _Private_Utils.newSharedSymtab(name, version, prior, syms.iterator());
    return st;
}
Also used : IonException(com.amazon.ion.IonException) ArrayList(java.util.ArrayList) SymbolTable(com.amazon.ion.SymbolTable) IonTextUtils.printString(com.amazon.ion.util.IonTextUtils.printString)

Example 63 with IonException

use of com.amazon.ion.IonException in project ion-java by amzn.

the class IonValueLite method toString.

@Override
public String toString() {
    StringBuilder buf = new StringBuilder(1024);
    try {
        Printer p = new Printer();
        p.print(this, buf);
    } catch (IOException e) {
        throw new IonException(e);
    }
    return buf.toString();
}
Also used : IonException(com.amazon.ion.IonException) IOException(java.io.IOException) Printer(com.amazon.ion.util.Printer)

Example 64 with IonException

use of com.amazon.ion.IonException in project ion-java by amzn.

the class Equivalence method compareLobContents.

/**
 * Compare LOB content by stream--assuming non-null.
 */
private static int compareLobContents(final IonLob lob1, final IonLob lob2) {
    int in1 = lob1.byteSize();
    int in2 = lob2.byteSize();
    int result = (in1 - in2);
    if (result == 0) {
        final InputStream stream1 = lob1.newInputStream();
        final InputStream stream2 = lob2.newInputStream();
        // too bad Java doesn't do RAII with better syntax...
        try {
            try {
                try {
                    while (result == 0) {
                        in1 = stream1.read();
                        in2 = stream2.read();
                        if (in1 == -1 || in2 == -1) {
                            if (in1 != -1)
                                result = 1;
                            if (in2 != -1)
                                result = -1;
                            break;
                        }
                        result = (in1 - in2);
                    }
                } finally {
                    stream1.close();
                }
            } finally {
                stream2.close();
            }
        } catch (final IOException e) {
            // this would violate Object.equals() would it not?
            throw new IonException(e);
        }
    }
    return result;
}
Also used : IonException(com.amazon.ion.IonException) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 65 with IonException

use of com.amazon.ion.IonException in project ion-java by amzn.

the class ByteBufferTest method testUnicodeCodepointOverflowStatic.

@Test
public void testUnicodeCodepointOverflowStatic() {
    OutputStream os = new ByteArrayOutputStream();
    try {
        IonBinary.writeString(os, new String(new char[] { 0xd799 }, 0, 1));
        IonBinary.writeString(os, new String(new char[] { 0xe000 }, 0, 1));
        // surrogates
        IonBinary.writeString(os, new String(new char[] { 0xd800, 0xdc00 }, 0, 2));
        IonBinary.writeString(os, new String(new char[] { 0xdbff, 0xdfff }, 0, 2));
    } catch (Exception e) {
        throw new IonException(e);
    }
    try {
        IonBinary.writeString(os, new String(new int[] { 0xd800 }, 0, 1));
        fail("Successfully parsed a partial surrogate");
    } catch (Exception e) {
    }
    try {
        IonBinary.writeString(os, new String(new int[] { 0xdfff }, 0, 1));
        fail("Successfully parsed a partial surrogate");
    } catch (Exception e) {
    }
}
Also used : IonException(com.amazon.ion.IonException) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IonException(com.amazon.ion.IonException) 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