Search in sources :

Example 36 with IonDatagram

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

the class PrinterTest method testJsonEscapeNonBmp.

@Test
public void testJsonEscapeNonBmp() throws Exception {
    final String literal = new StringBuilder().append("'''").append('\uDAF7').append('\uDE56').append("'''").toString();
    final byte[] utf8Bytes = _Private_Utils.utf8(literal);
    final IonDatagram dg = loader().load(utf8Bytes);
    final StringBuilder out = new StringBuilder();
    final Printer json = new Printer();
    json.setJsonMode();
    json.print(dg.get(0), out);
    assertEquals("\"\\uDAF7\\uDE56\"".toLowerCase(), out.toString().toLowerCase());
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonString(com.amazon.ion.IonString) Test(org.junit.Test) IntTest(com.amazon.ion.IntTest) BlobTest(com.amazon.ion.BlobTest) ClobTest(com.amazon.ion.ClobTest)

Example 37 with IonDatagram

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

the class ReaderDomCopyTest method iterateIon.

void iterateIon(File myTestFile) throws IOException {
    IonDatagram dg = system().getLoader().load(myTestFile);
    IonReader reader = system().newReader(dg);
    for (int i = 0; reader.next() != null; i++) {
        IonValue actual = system().newValue(reader);
        assertIonEquals(dg.get(i), actual);
    }
}
Also used : IonValue(com.amazon.ion.IonValue) IonDatagram(com.amazon.ion.IonDatagram) IonReader(com.amazon.ion.IonReader)

Example 38 with IonDatagram

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

the class MiscStreamingTest method testBinaryAnnotation.

@Test
public void testBinaryAnnotation() throws Exception {
    String s = "item_view::{item_id:\"B00096H8Q4\",marketplace_id:2," + "product:{item_name:[" + "{value:'''Method 24CT Leather Wipes''',lang:EN_CA}," + "{value:'''Method 24CT Chiffons de Cuir''',lang:FR_CA}]," + "list_price:{value:18.23,unit:EUR},}" + ",index_suppressed:true," + "offline_store_only:true,version:2,}";
    IonSystem sys = system();
    IonDatagram dg = sys.getLoader().load(s);
    IonValue v = dg.get(0);
    IonType t = v.getType();
    assertSame("should be a struct", t, IonType.STRUCT);
    // first make sure the ion tree got it right
    assertTrue(v.hasTypeAnnotation("item_view"));
    String[] ann = v.getTypeAnnotations();
    assertTrue(ann.length == 1 && ann[0].equals("item_view"));
    // now take the string and get a text iterator and
    // make sure it got the annotation right
    IonReader it = system().newReader(s);
    t = it.next();
    assertSame("should be a struct", t, IonType.STRUCT);
    ann = it.getTypeAnnotations();
    assertTrue(ann.length == 1 && ann[0].equals("item_view"));
    // finally get the byte array from the tree, make a
    // binary iterator and check its annotation handling
    byte[] buf = dg.getBytes();
    it = system().newReader(buf);
    t = it.next();
    assertSame("should be a struct", t, IonType.STRUCT);
    ann = it.getTypeAnnotations();
    assertTrue(ann.length == 1 && ann[0].equals("item_view"));
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) IonType(com.amazon.ion.IonType) IonDatagram(com.amazon.ion.IonDatagram) IonReader(com.amazon.ion.IonReader) IonString(com.amazon.ion.IonString) Test(org.junit.Test) BinaryTest(com.amazon.ion.BinaryTest)

Example 39 with IonDatagram

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

the class OffsetSpanBinaryReaderTest method testCurrentSpanBeyondMaxInt.

@Test
public void testCurrentSpanBeyondMaxInt() {
    if (getStreamingMode() == StreamingMode.NEW_STREAMING_INCREMENTAL) {
        // See ion-java/issues/382 and ion-java/issues/383.
        return;
    }
    IonDatagram dg = system().newDatagram();
    dg.add().newBlob(new byte[2000]);
    byte[] binary = dg.getBytes();
    readBeyondMaxInt(binary, IonType.BLOB);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 40 with IonDatagram

use of com.amazon.ion.IonDatagram in project jackson-dataformats-binary by FasterXML.

the class DataBindWriteTest method testSimpleObjectWriteBinary.

@Test
public void testSimpleObjectWriteBinary() throws Exception {
    byte[] data = _writeAsBytes(new MyBean());
    IonDatagram loadedDatagram = ion.newLoader().load(data);
    assertEquals(expectedMyBean, loadedDatagram);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Aggregations

IonDatagram (com.amazon.ion.IonDatagram)92 Test (org.junit.Test)77 IonValue (com.amazon.ion.IonValue)20 SymbolTable (com.amazon.ion.SymbolTable)18 IonReader (com.amazon.ion.IonReader)17 IonString (com.amazon.ion.IonString)15 IonStruct (com.amazon.ion.IonStruct)13 IonWriter (com.amazon.ion.IonWriter)11 IonSymbol (com.amazon.ion.IonSymbol)6 IonSystem (com.amazon.ion.IonSystem)6 IonLoader (com.amazon.ion.IonLoader)5 IonType (com.amazon.ion.IonType)5 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)5 BlobTest (com.amazon.ion.BlobTest)4 ClobTest (com.amazon.ion.ClobTest)4 IntTest (com.amazon.ion.IntTest)4 IonList (com.amazon.ion.IonList)4 IonTextWriterBuilder (com.amazon.ion.system.IonTextWriterBuilder)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 BinaryTest (com.amazon.ion.BinaryTest)2