use of co.cask.cdap.common.io.BinaryEncoder in project cdap by caskdata.
the class QueueEntry method serializeHashKeys.
public static byte[] serializeHashKeys(Map<String, Integer> hashKeys) throws IOException {
// many entries will have no hash keys. Reuse a static value for that
if (hashKeys == null || hashKeys.isEmpty()) {
return SERIALIZED_EMPTY_HASH_KEYS;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Encoder encoder = new BinaryEncoder(bos);
encoder.writeInt(hashKeys.size());
for (Map.Entry<String, Integer> entry : hashKeys.entrySet()) {
encoder.writeString(entry.getKey()).writeInt(entry.getValue());
}
// per Avro spec, end with a (block of length) zero
encoder.writeInt(0);
return bos.toByteArray();
}
use of co.cask.cdap.common.io.BinaryEncoder in project cdap by caskdata.
the class DatumOutputEmitter method emit.
@Override
public void emit(T data, Map<String, Object> partitions) {
try {
ByteArrayOutputStream output = new ByteArrayOutputStream();
output.write(schemaHash);
writer.encode(data, new BinaryEncoder(output));
producerSupplier.get().enqueue(new QueueEntry(Maps.transformValues(partitions, PARTITION_MAP_TRANSFORMER), output.toByteArray()));
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
Aggregations