Search in sources :

Example 26 with IonDatagram

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

the class OptimizedBinaryWriterSymbolTableTest method testOptimizedWriteValueSubsetWriterLST2.

/**
 * Writer's LST subset of Reader's - no optimize.
 * Reader's symtab has a gap at the end.
 */
@Test
public void testOptimizedWriteValueSubsetWriterLST2() throws Exception {
    // Create reader with LST with a gap at the end
    String readerLST = printLocalSymtab("amazon", "website", null);
    byte[] source = encode(readerLST + "amazon website");
    ir = makeReaderProxy(source);
    iw = makeWriterWithLocalSymtab("amazon", "website");
    // amazon
    checkWriteValueWithIncompatibleSymtab();
    // website
    checkWriteValueWithIncompatibleSymtab();
    iw.close();
    IonDatagram expected = loader().load("amazon website");
    IonDatagram actual = loader().load(outputByteArray());
    assertIonEquals(expected, actual);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 27 with IonDatagram

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

the class OptimizedBinaryWriterSymbolTableTest method testOptimizedWriteValueSupersetWriterLST1.

/**
 * Writer's LST superset of Reader's - optimize.
 */
@Test
public void testOptimizedWriteValueSupersetWriterLST1() throws Exception {
    String readerLST = printLocalSymtab("amazon");
    byte[] source = encode(readerLST + "amazon");
    ir = makeReaderProxy(source);
    iw = makeWriterWithLocalSymtab("amazon", "website");
    // amazon
    checkWriteValueWithCompatibleSymtab();
    iw.close();
    IonDatagram expected = loader().load("amazon");
    IonDatagram actual = loader().load(outputByteArray());
    assertIonEquals(expected, actual);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 28 with IonDatagram

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

the class OptimizedBinaryWriterSymbolTableTest method testOptimizedWriteValueSupersetWriterLST2.

/**
 * Writer's LST superset of Reader's - optimize.
 * Writer's symtab has a gap at the end.
 */
@Test
public void testOptimizedWriteValueSupersetWriterLST2() throws Exception {
    String readerLST = printLocalSymtab("amazon", "website");
    byte[] source = encode(readerLST + "amazon website");
    ir = makeReaderProxy(source);
    iw = makeWriterWithLocalSymtab("amazon", "website", null);
    // amazon
    checkWriteValueWithCompatibleSymtab();
    // website
    checkWriteValueWithCompatibleSymtab();
    iw.close();
    IonDatagram expected = loader().load("amazon website");
    IonDatagram actual = loader().load(outputByteArray());
    assertIonEquals(expected, actual);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 29 with IonDatagram

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

the class OptimizedBinaryWriterSymbolTableTest method testOptimizedWriteValueSubsetWriterLST1.

/**
 * Writer's LST subset of Reader's - no optimize.
 */
@Test
public void testOptimizedWriteValueSubsetWriterLST1() throws Exception {
    String readerLST = printLocalSymtab("amazon", "website");
    byte[] source = encode(readerLST + "amazon website");
    ir = makeReaderProxy(source);
    iw = makeWriterWithLocalSymtab("amazon");
    // amazon
    checkWriteValueWithIncompatibleSymtab();
    // website
    checkWriteValueWithIncompatibleSymtab();
    iw.close();
    IonDatagram expected = loader().load("amazon website");
    IonDatagram actual = loader().load(outputByteArray());
    assertIonEquals(expected, actual);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 30 with IonDatagram

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

the class IonSystemLite method clone.

@SuppressWarnings("unchecked")
public <T extends IonValue> T clone(T value) throws IonException {
    // Use "fast clone" when the system is the same.
    if (value.getSystem() == this) {
        return (T) value.clone();
    }
    if (value instanceof IonDatagram) {
        IonDatagram datagram = newDatagram();
        IonWriter writer = _Private_IonWriterFactory.makeWriter(datagram);
        IonReader reader = makeSystemReader(value.getSystem(), value);
        try {
            writer.writeValues(reader);
        } catch (IOException e) {
            throw new IonException(e);
        }
        return (T) datagram;
    }
    IonReader reader = newReader(value);
    reader.next();
    return (T) newValue(reader);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonException(com.amazon.ion.IonException) IonReader(com.amazon.ion.IonReader) IonWriter(com.amazon.ion.IonWriter) IOException(java.io.IOException)

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