Search in sources :

Example 1 with IonString

use of com.amazon.ion.IonString in project amazon-qldb-dmv-sample-java by aws-samples.

the class JournalS3ExportReader method getDataFileKeysFromManifest.

/**
 * Given the S3Object to the completed manifest file, return the keys
 * which are part of this export request.
 *
 * @param s3Object
 *              A {@link S3Object}.
 * @return a list of data file keys containing the chunk of {@link JournalBlock}.
 */
private static List<String> getDataFileKeysFromManifest(final S3Object s3Object) {
    IonReader ionReader = IonReaderBuilder.standard().build(s3Object.getObjectContent());
    // Read the data
    ionReader.next();
    List<String> keys = new ArrayList<>();
    IonStruct ionStruct = (IonStruct) SYSTEM.newValue(ionReader);
    IonList ionKeysList = (IonList) ionStruct.get("keys");
    ionKeysList.forEach(key -> keys.add(((IonString) key).stringValue()));
    return keys;
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonString(com.amazon.ion.IonString) IonList(com.amazon.ion.IonList) IonReader(com.amazon.ion.IonReader) ArrayList(java.util.ArrayList) IonString(com.amazon.ion.IonString)

Example 2 with IonString

use of com.amazon.ion.IonString in project amazon-qldb-dmv-sample-java by aws-samples.

the class RevisionMetadata method fromIon.

public static RevisionMetadata fromIon(final IonStruct ionStruct) {
    if (ionStruct == null) {
        throw new IllegalArgumentException("Metadata cannot be null");
    }
    try {
        IonString id = (IonString) ionStruct.get("id");
        IonInt version = (IonInt) ionStruct.get("version");
        IonTimestamp txTime = (IonTimestamp) ionStruct.get("txTime");
        IonString txId = (IonString) ionStruct.get("txId");
        if (id == null || version == null || txTime == null || txId == null) {
            throw new IllegalArgumentException("Document is missing required fields");
        }
        return new RevisionMetadata(id.stringValue(), version.longValue(), new Date(txTime.getMillis()), txId.stringValue());
    } catch (ClassCastException e) {
        log.error("Failed to parse ion document");
        throw new IllegalArgumentException("Document members are not of the correct type", e);
    }
}
Also used : IonString(com.amazon.ion.IonString) IonTimestamp(com.amazon.ion.IonTimestamp) IonInt(com.amazon.ion.IonInt) Date(java.util.Date)

Example 3 with IonString

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

the class _Private_CurriedValueFactory method newString.

public IonString newString(String value) {
    IonString v = myFactory.newString(value);
    handle(v);
    return v;
}
Also used : IonString(com.amazon.ion.IonString)

Example 4 with IonString

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

the class SimpleCatalogTest method testBenchmark.

@SuppressWarnings("unchecked")
@Test
public void testBenchmark() {
    Map m = new HashMap();
    String s = "hello";
    m.put("This is a test String.", true);
    m.put(s, true);
    m.put("true", true);
    m.put("false", false);
    m.put("Something", null);
    m.put("12242.124598129", 12242.124598129);
    m.put("long", (long) 9326);
    m.put("12", 12);
    m.put("Almost Done.", true);
    m.put("Date", new Date(-10000));
    HashMap<String, String> hmap = new HashMap();
    for (int i = 0; i < 10; i++) {
        hmap.put("Key " + i, "value " + i);
    }
    TreeMap<String, String> tmap = new TreeMap();
    for (int i = 0; i < 10; i++) {
        tmap.put("Key " + i, "value " + i);
    }
    m.put("hmap", hmap);
    m.put("tmap", tmap);
    IonSystem sys = system();
    IonStruct i_tmap, i_hmap, i_map;
    Set<Entry<String, String>> set;
    i_tmap = sys.newEmptyStruct();
    set = tmap.entrySet();
    for (Entry<String, String> e : set) {
        IonString is = sys.newString(e.getValue());
        i_tmap.add(e.getKey(), is);
    }
    i_hmap = sys.newEmptyStruct();
    set = hmap.entrySet();
    for (Entry<String, String> e : set) {
        IonString is = sys.newString(e.getValue());
        i_hmap.add(e.getKey(), is);
    }
    i_map = sys.newEmptyStruct();
    set = tmap.entrySet();
    for (Entry<String, String> e : set) {
        Object val = e.getValue();
        IonValue ival;
        if (val instanceof String) {
            ival = sys.newString((String) val);
        } else if (e.getKey().equals("tmap")) {
            ival = i_tmap;
        } else if (e.getKey().equals("hmap")) {
            ival = i_hmap;
        } else {
            throw new RuntimeException("ACK! there's something in this map I don't understand!");
        }
        i_map.add(e.getKey(), ival);
    }
    IonDatagram dg = sys.newDatagram(i_map);
    byte[] bytes = dg.getBytes();
    IonValue v2 = sys.singleValue(bytes);
    assertNotNull(v2);
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) HashMap(java.util.HashMap) IonString(com.amazon.ion.IonString) TreeMap(java.util.TreeMap) Date(java.util.Date) Entry(java.util.Map.Entry) IonStruct(com.amazon.ion.IonStruct) IonString(com.amazon.ion.IonString) IonDatagram(com.amazon.ion.IonDatagram) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with IonString

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

the class IonWriterSystemTree method writeString.

public void writeString(String value) throws IOException {
    IonString v = _factory.newString(value);
    append(v);
}
Also used : IonString(com.amazon.ion.IonString)

Aggregations

IonString (com.amazon.ion.IonString)13 Test (org.junit.Test)6 IonStruct (com.amazon.ion.IonStruct)5 IonDatagram (com.amazon.ion.IonDatagram)3 BlobTest (com.amazon.ion.BlobTest)2 ClobTest (com.amazon.ion.ClobTest)2 IntTest (com.amazon.ion.IntTest)2 IonInt (com.amazon.ion.IonInt)2 IonList (com.amazon.ion.IonList)2 IonReader (com.amazon.ion.IonReader)2 IonTimestamp (com.amazon.ion.IonTimestamp)2 Date (java.util.Date)2 BinaryTest (com.amazon.ion.BinaryTest)1 IonBlob (com.amazon.ion.IonBlob)1 IonBool (com.amazon.ion.IonBool)1 IonClob (com.amazon.ion.IonClob)1 IonDecimal (com.amazon.ion.IonDecimal)1 IonFloat (com.amazon.ion.IonFloat)1 IonLoader (com.amazon.ion.IonLoader)1 IonNull (com.amazon.ion.IonNull)1