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);
}
}
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;
}
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();
}
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;
}
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) {
}
}
Aggregations