use of com.amazon.ion.impl.bin._Private_IonRawWriter in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method bigInts.
@Test
public void bigInts() throws Exception {
IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {
@Override
public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
writer.writeInt(0);
writer.writeInt(-1);
writer.writeInt(1);
writer.writeInt((long) Integer.MAX_VALUE + 1);
writer.writeInt((long) Integer.MIN_VALUE - 1);
// Just shy of the boundary.
writer.writeInt(Long.MIN_VALUE + 1);
writer.writeInt(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE));
writer.writeInt(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE));
writer.close();
out.write(bytes(0x38, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
}
});
assertEquals(IonType.INT, reader.next());
assertEquals(IntegerSize.INT, reader.getIntegerSize());
assertEquals(BigInteger.ZERO, reader.bigIntegerValue());
assertEquals(IonType.INT, reader.next());
assertEquals(IntegerSize.INT, reader.getIntegerSize());
assertEquals(BigInteger.ONE.negate(), reader.bigIntegerValue());
assertEquals(IonType.INT, reader.next());
assertEquals(IntegerSize.INT, reader.getIntegerSize());
assertEquals(BigInteger.ONE, reader.bigIntegerValue());
assertEquals(IonType.INT, reader.next());
assertEquals(IntegerSize.LONG, reader.getIntegerSize());
assertEquals(BigInteger.valueOf(Integer.MAX_VALUE).add(BigInteger.ONE), reader.bigIntegerValue());
assertEquals(IonType.INT, reader.next());
assertEquals(IntegerSize.LONG, reader.getIntegerSize());
assertEquals(BigInteger.valueOf(Integer.MIN_VALUE).subtract(BigInteger.ONE), reader.bigIntegerValue());
assertEquals(IonType.INT, reader.next());
assertEquals(IntegerSize.LONG, reader.getIntegerSize());
assertEquals(Long.MIN_VALUE + 1, reader.longValue());
assertEquals(IonType.INT, reader.next());
assertEquals(IntegerSize.BIG_INTEGER, reader.getIntegerSize());
assertEquals(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE), reader.bigIntegerValue());
assertEquals(IonType.INT, reader.next());
assertEquals(IntegerSize.BIG_INTEGER, reader.getIntegerSize());
assertEquals(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE), reader.bigIntegerValue());
assertEquals(IonType.INT, reader.next());
assertEquals(IntegerSize.BIG_INTEGER, reader.getIntegerSize());
assertEquals(new BigInteger(-1, bytes(0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)), reader.bigIntegerValue());
assertNull(reader.next());
reader.close();
}
use of com.amazon.ion.impl.bin._Private_IonRawWriter in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method readerFor.
/**
* Creates an incremental reader over the binary Ion data created by invoking the given RawWriterFunction.
* @param writerFunction the function used to generate the data.
* @return a new reader.
* @throws Exception if an exception is raised while writing the Ion data.
*/
private IonReaderBinaryIncremental readerFor(RawWriterFunction writerFunction) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
_Private_IonRawWriter writer = writerBuilder.build(out).asFacet(_Private_IonManagedWriter.class).getRawWriter();
out.write(_Private_IonConstants.BINARY_VERSION_MARKER_1_0);
writerFunction.write(writer, out);
writer.close();
return new IonReaderBinaryIncremental(readerBuilder, new ByteArrayInputStream(out.toByteArray()));
}
use of com.amazon.ion.impl.bin._Private_IonRawWriter in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method nonStringInSymbolsListCreatesNullSlot.
@Test
public void nonStringInSymbolsListCreatesNullSlot() throws Exception {
IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {
@Override
public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
writer.stepIn(IonType.LIST);
writer.writeString(null);
writer.writeString("abc");
writer.writeInt(123);
writer.stepOut();
writer.stepOut();
writer.writeSymbolToken(10);
writer.writeSymbolToken(11);
writer.writeSymbolToken(12);
}
});
assertEquals(IonType.SYMBOL, reader.next());
SymbolToken symbolValue = reader.symbolValue();
assertNull(symbolValue.getText());
assertEquals(0, symbolValue.getSid());
assertEquals(IonType.SYMBOL, reader.next());
symbolValue = reader.symbolValue();
assertEquals("abc", symbolValue.getText());
assertEquals(IonType.SYMBOL, reader.next());
symbolValue = reader.symbolValue();
assertNull(symbolValue.getText());
assertEquals(0, symbolValue.getSid());
reader.close();
}
use of com.amazon.ion.impl.bin._Private_IonRawWriter in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method symbolTableWithSymbolsThenImports.
@Test
public void symbolTableWithSymbolsThenImports() throws Exception {
SimpleCatalog catalog = new SimpleCatalog();
catalog.putTable(SYSTEM.newSharedSymbolTable("foo", 1, Arrays.asList("abc", "def").iterator()));
readerBuilder = IonReaderBuilder.standard().withCatalog(catalog);
IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {
@Override
public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
writer.stepIn(IonType.LIST);
writer.writeString("ghi");
writer.stepOut();
writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
writer.stepIn(IonType.LIST);
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("name"));
writer.writeString("foo");
writer.setFieldNameSymbol(systemTable.findSymbol("version"));
writer.writeInt(1);
writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
writer.writeInt(2);
writer.stepOut();
writer.stepOut();
writer.stepOut();
writer.writeSymbolToken(10);
writer.writeSymbolToken(11);
writer.writeSymbolToken(12);
}
});
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("abc", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("def", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("ghi", reader.stringValue());
assertNull(reader.next());
reader.close();
}
use of com.amazon.ion.impl.bin._Private_IonRawWriter in project ion-java by amzn.
the class IonRawWriterBasicTest method basicRawWriter.
private _Private_IonRawWriter basicRawWriter() {
IonWriter writer = writer(new ByteArrayOutputStream());
_Private_IonManagedWriter managedWriter = Facets.assumeFacet(_Private_IonManagedWriter.class, writer);
return managedWriter.getRawWriter();
}
Aggregations