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;
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations