use of com.amazon.ion.IonDatagram in project jackson-dataformats-binary by FasterXML.
the class SimpleIonWriteTest method ionTextCompare.
private void ionTextCompare(String generatedTextIon) {
IonLoader loader = ion.newLoader();
IonDatagram loadedDatagram = loader.load(generatedTextIon);
// the expected value is always the same {a:"value",b:42}
assertEquals(expected, loadedDatagram);
}
use of com.amazon.ion.IonDatagram in project jackson-dataformats-binary by FasterXML.
the class SimpleIonWriteTest method ionBinaryCompare.
private void ionBinaryCompare(byte[] generatedBinaryIon) {
IonLoader loader = ion.newLoader();
IonDatagram loadedDatagram = loader.load(generatedBinaryIon);
// the expected value is always the same {a:"value",b:42}
assertEquals(expected, loadedDatagram);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonReaderTreeUserX method next_helper_user.
boolean next_helper_user() {
if (_eof)
return false;
if (_next != null)
return true;
clear_system_value_stack();
// read values from the system
// reader and if they are system values
// process them. Return when we've
// read all the immediate system values
IonType next_type;
for (; ; ) {
next_type = next_helper_system();
if (_top == 0 && _parent instanceof IonDatagram) {
if (IonType.SYMBOL.equals(next_type)) {
assert (_next instanceof IonSymbol);
IonSymbol sym = (IonSymbol) _next;
if (sym.isNullValue()) {
// there are no null values we will consume here
break;
}
int sid = sym.getSymbolId();
if (sid == UNKNOWN_SYMBOL_ID) {
String name = sym.stringValue();
if (name != null) {
sid = _system_symtab.findSymbol(name);
}
}
if (sid == ION_1_0_SID && _next.getTypeAnnotationSymbols().length == 0) {
// $ion_1_0 is read as an IVM only if it is not annotated
SymbolTable symbols = _system_symtab;
_symbols = symbols;
push_symbol_table(symbols);
_next = null;
continue;
}
} else if (IonType.STRUCT.equals(next_type) && _next.findTypeAnnotation(ION_SYMBOL_TABLE) == 0) {
assert (_next instanceof IonStruct);
// read a local symbol table
IonReader reader = new IonReaderTreeUserX(_next, _catalog, _lstFactory);
SymbolTable symtab = _lstFactory.newLocalSymtab(_catalog, reader, false);
_symbols = symtab;
push_symbol_table(symtab);
_next = null;
continue;
}
}
// so this is a value the user gets
break;
}
return (next_type != null);
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class IonReaderLookaheadBufferTest method skipOversizedValues.
@Test
public void skipOversizedValues() throws Exception {
if (initialBufferSize == null) {
// of the buffer is unlimited. Skip.
return;
}
// 14 values ranging in size from 1-14 bytes. There are 14 - x values larger than x bytes.
TestUtils.BinaryIonAppender appender = new TestUtils.BinaryIonAppender().append(// boolean true
0x11, // int 0 (overpadded)
0x21, // int 0 (overpadded)
0x00, // int 1 (overpadded)
0x22, // int 1 (overpadded)
0x00, // int 1 (overpadded)
0x01, // int -2 (overpadded)
0x33, // int -2 (overpadded)
0x00, // int -2 (overpadded)
0x00, // int -2 (overpadded)
0x02, // float 0e0
0x44, // float 0e0
0x00, // float 0e0
0x00, // float 0e0
0x00, // float 0e0
0x00, // decimal 0d0 (overpadded)
0x55, // decimal 0d0 (overpadded)
0x00, // decimal 0d0 (overpadded)
0x00, // decimal 0d0 (overpadded)
0x80, // decimal 0d0 (overpadded)
0x00, // decimal 0d0 (overpadded)
0x00, // timestamp 0001-01-01T00:00Z
0x66, // timestamp 0001-01-01T00:00Z
0x80, // timestamp 0001-01-01T00:00Z
0x81, // timestamp 0001-01-01T00:00Z
0x81, // timestamp 0001-01-01T00:00Z
0x81, // timestamp 0001-01-01T00:00Z
0x80, // timestamp 0001-01-01T00:00Z
0x80, // symbol 0 (overpadded length and value)
0x7E, // symbol 0 (overpadded length and value)
0x00, // symbol 0 (overpadded length and value)
0x00, // symbol 0 (overpadded length and value)
0x00, // symbol 0 (overpadded length and value)
0x00, // symbol 0 (overpadded length and value)
0x82, // symbol 0 (overpadded length and value)
0x00, // symbol 0 (overpadded length and value)
0x00, // string abcdefgh
0x88, // string abcdefgh
'a', // string abcdefgh
'b', // string abcdefgh
'c', // string abcdefgh
'd', // string abcdefgh
'e', // string abcdefgh
'f', // string abcdefgh
'g', // string abcdefgh
'h', // clob abcdefghi
0x99, // clob abcdefghi
'a', // clob abcdefghi
'b', // clob abcdefghi
'c', // clob abcdefghi
'd', // clob abcdefghi
'e', // clob abcdefghi
'f', // clob abcdefghi
'g', // clob abcdefghi
'h', // clob abcdefghi
'i', // blob
0xAA, // blob
0x01, // blob
0x02, // blob
0x03, // blob
0x04, // blob
0x05, // blob
0x06, // blob
0x07, // blob
0x08, // blob
0x09, // blob
0x0A, // list with ten int 0
0xBB, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, // sexp with ten decimal 0d0
0xCC, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, // struct with system symbol field names and int 0 values (some overpadded)
0xDD, 0x84, 0x20, 0x85, 0x20, 0x86, 0x20, 0x87, 0x21, 0x00, 0x88, 0x22, 0x00, 0x00);
byte[] data = appender.toByteArray();
IonDatagram expectedValues = SYSTEM.getLoader().load(data);
;
for (int maxValueSize : Arrays.asList(5, 7, 8, 10, 13)) {
if (maxValueSize < initialBufferSize) {
// This would violate the IonBufferConfiguration contract; no need to test here.
continue;
}
ByteArrayInputStream input = new ByteArrayInputStream(data);
RecordingEventHandler eventHandler = new RecordingEventHandler();
IonBufferConfiguration.Builder builder = IonBufferConfiguration.Builder.standard().withMaximumBufferSize(maxValueSize).onOversizedValue(eventHandler).onOversizedSymbolTable(eventHandler).onData(eventHandler).withInitialBufferSize(initialBufferSize);
IonReaderLookaheadBuffer lookahead = new IonReaderLookaheadBuffer(builder.build(), input);
IonReader reader = null;
try {
int valueIndex = 0;
while (true) {
lookahead.fillInput();
if (lookahead.moreDataRequired()) {
break;
}
if (reader == null) {
reader = lookahead.newIonReader(IonReaderBuilder.standard());
}
assertNotNull(reader.next());
assertTrue(Equivalence.ionEquals(expectedValues.get(valueIndex), SYSTEM.newValue(reader)));
valueIndex++;
}
// There is one value per size. For a max size of x, `moreDataRequired` should be false x times.
assertEquals(valueIndex, maxValueSize);
} finally {
if (reader != null) {
reader.close();
}
}
int expectedOversizedValues = expectedValues.size() - maxValueSize;
assertEquals(String.format("Expect %d oversized values for max size %d", expectedOversizedValues, maxValueSize), expectedOversizedValues, eventHandler.oversizedValueCount);
assertEquals(0, eventHandler.oversizedSymbolTableCount);
ResizingPipedInputStream buffer = (ResizingPipedInputStream) lookahead.getPipe();
// The buffer grows in increments of its initial buffer size. Therefore, the final capacity will be at
// most `initialBufferSize` larger than the lookahead wrapper's configured max value size.
assertTrue(buffer.capacity() <= maxValueSize + buffer.getInitialBufferSize());
}
}
use of com.amazon.ion.IonDatagram in project ion-java by amzn.
the class OptimizedBinaryWriterLengthPatchingTest method testOptimizedWriteValueBetweenContainers.
/**
* Test copy optimized writeValue when the IonReader is stepped-in.
*/
@Test
public void testOptimizedWriteValueBetweenContainers() throws Exception {
String body = // struct
"{ fred_1: 123, fred_1: fred_1, fred_1: fred_1::null } " + // list
"[ 123, fred_1, fred_1::null ] " + // sexp
"( 123 fred_1 fred_1::null ) " + // deeply nested list
"[[[ 123, fred_1, fred_1::null ]]]" + // list
"[ 123, fred_1, fred_1::null ]";
byte[] source = encode(body);
ir = makeReaderProxy(source);
iw = makeWriter();
// Prime the local symtab so it matches the source's symtab
iw.writeSymbol("fred_1");
// === Struct ===
copyContainerElements();
// === List ===
copyContainerElements();
// === Sexp ===
copyContainerElements();
// === deeply nested List ===
ir.next();
ir.stepIn();
{
ir.next();
ir.stepIn();
{
copyContainerElements();
}
ir.stepOut();
}
ir.stepOut();
// === copy to a stepped-in-sexp writer ===
iw.stepIn(IonType.SEXP);
{
copyContainerElements();
}
iw.stepOut();
// Create the expected Ion data as text, which will be loaded into
// a datagram later for equality check.
StringBuilder sb = new StringBuilder();
// scalars in each container
String scalars = "123 fred_1 fred_1::null ";
// from priming of local symtab
sb.append("fred_1 ");
// from struct
sb.append(scalars);
// from list
sb.append(scalars);
// from sexp
sb.append(scalars);
// from deeply nested list
sb.append(scalars);
// stepped-in-sexp writer
sb.append("(" + scalars + ")");
String expectedIonText = sb.toString();
IonDatagram expected = loader().load(expectedIonText);
IonDatagram actual = loader().load(outputByteArray());
assertIonEquals(expected, actual);
}
Aggregations