MCPcopy
hub / github.com/OpenTSDB/opentsdb / getStorageJSON

Method getStorageJSON

src/meta/Annotation.java:517–545  ·  view source on GitHub ↗

Serializes the object in a uniform matter for storage. Needed for successful CAS calls @return The serialized object as a byte array

()

Source from the content-addressed store, hash-verified

515 * @return The serialized object as a byte array
516 */
517 @VisibleForTesting
518 byte[] getStorageJSON() {
519 // TODO - precalculate size
520 final ByteArrayOutputStream output = new ByteArrayOutputStream();
521 try {
522 final JsonGenerator json = JSON.getFactory().createGenerator(output);
523 json.writeStartObject();
524 if (tsuid != null && !tsuid.isEmpty()) {
525 json.writeStringField("tsuid", tsuid);
526 }
527 json.writeNumberField("startTime", start_time);
528 json.writeNumberField("endTime", end_time);
529 json.writeStringField("description", description);
530 json.writeStringField("notes", notes);
531 if (custom == null) {
532 json.writeNullField("custom");
533 } else {
534 final TreeMap<String, String> sorted_custom =
535 new TreeMap<String, String>(custom);
536 json.writeObjectField("custom", sorted_custom);
537 }
538
539 json.writeEndObject();
540 json.close();
541 return output.toByteArray();
542 } catch (IOException e) {
543 throw new RuntimeException("Unable to serialize Annotation", e);
544 }
545 }
546
547 /**
548 * Syncs the local object with the stored object for atomic writes,

Callers 1

callMethod · 0.45

Calls 5

getFactoryMethod · 0.95
isEmptyMethod · 0.80
toByteArrayMethod · 0.80
writeStringFieldMethod · 0.65
closeMethod · 0.45

Tested by

no test coverage detected