Search in sources :

Example 31 with IonSystem

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

the class MiscStreamingTest method testValue2.

@Test
public void testValue2() 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", IonType.STRUCT, t);
    int tree_count = ((IonStruct) v).size();
    IonReader it = system().newReader(s);
    t = it.next();
    assertSame("should be a struct", IonType.STRUCT, t);
    int string_count = 0;
    it.stepIn();
    while (it.next() != null) {
        string_count++;
    }
    it.stepOut();
    assertSame("tree and string iterator should have the same size", tree_count, string_count);
    byte[] buf = dg.getBytes();
    it = system().newReader(buf);
    t = it.next();
    assertSame("should be a struct", IonType.STRUCT, t);
    int bin_count = 0;
    it.stepIn();
    while (it.next() != null) {
        bin_count++;
    }
    it.stepOut();
    assertSame("tree and binary iterator should have the same size", tree_count, bin_count);
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) IonStruct(com.amazon.ion.IonStruct) 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 32 with IonSystem

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

the class IonBinaryWriterBuilderTest method testSetIsFloatBinary32Enabled.

// -------------------------------------------------------------------------
@Test
public void testSetIsFloatBinary32Enabled() throws IOException {
    IonSystem system = IonSystemBuilder.standard().build();
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard();
    b.setIsFloatBinary32Enabled(true);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    writer.writeFloat(1.0);
    writer.close();
    assertEquals(9, out.size());
    assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
    b.setIsFloatBinary32Enabled(false);
    out = new ByteArrayOutputStream();
    writer = b.build(out);
    writer.writeFloat(1.0);
    writer.close();
    assertEquals(13, out.size());
    assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
}
Also used : IonSystem(com.amazon.ion.IonSystem) com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 33 with IonSystem

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

the class IonBinaryWriterBuilderTest method testSymtabValueFactory.

// -------------------------------------------------------------------------
@Test
public void testSymtabValueFactory() {
    IonSystem system = IonSystemBuilder.standard().build();
    _Private_IonBinaryWriterBuilder b = _Private_IonBinaryWriterBuilder.standard();
    b.setSymtabValueFactory(system);
    assertSame(system, b.getSymtabValueFactory());
// The value factory isn't visible through other APIs so we can't
// really test any further.
}
Also used : IonSystem(com.amazon.ion.IonSystem) com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) Test(org.junit.Test)

Example 34 with IonSystem

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

the class IonBinaryWriterBuilderTest method testWithFloatBinary32Enabled.

@Test
public void testWithFloatBinary32Enabled() throws IOException {
    IonSystem system = IonSystemBuilder.standard().build();
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard().withFloatBinary32Enabled();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    writer.writeFloat(1.0);
    writer.close();
    assertEquals(9, out.size());
    assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
}
Also used : IonSystem(com.amazon.ion.IonSystem) com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 35 with IonSystem

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

the class IonBinaryWriterBuilderTest method testWithFloatBinary32Disabled.

@Test
public void testWithFloatBinary32Disabled() throws IOException {
    IonSystem system = IonSystemBuilder.standard().build();
    IonBinaryWriterBuilder b = IonBinaryWriterBuilder.standard().withFloatBinary32Disabled();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IonWriter writer = b.build(out);
    writer.writeFloat(1.0);
    writer.close();
    assertEquals(13, out.size());
    assertEquals(system.newFloat(1.0), system.singleValue(out.toByteArray()));
}
Also used : IonSystem(com.amazon.ion.IonSystem) com.amazon.ion.impl._Private_IonBinaryWriterBuilder(com.amazon.ion.impl._Private_IonBinaryWriterBuilder) IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonWriter(com.amazon.ion.impl._Private_IonWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

IonSystem (com.amazon.ion.IonSystem)39 Test (org.junit.Test)27 IonValue (com.amazon.ion.IonValue)12 SymbolTable (com.amazon.ion.SymbolTable)10 IonReader (com.amazon.ion.IonReader)8 IonWriter (com.amazon.ion.IonWriter)8 IonDatagram (com.amazon.ion.IonDatagram)6 IonStruct (com.amazon.ion.IonStruct)6 IonCatalog (com.amazon.ion.IonCatalog)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 IonString (com.amazon.ion.IonString)4 com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)4 com.amazon.ion.impl._Private_IonWriter (com.amazon.ion.impl._Private_IonWriter)4 BinaryTest (com.amazon.ion.BinaryTest)3 IonBinaryWriter (com.amazon.ion.IonBinaryWriter)2 IonType (com.amazon.ion.IonType)2 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)2 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 Date (java.util.Date)2