use of org.rcsb.mmtf.encoder.GenericEncoder in project mmtf-spark by sbl-sdsc.
the class MmtfWriter method toByteArray.
/**
* Returns an MMTF-encoded byte array with optional gzip compression.
* @return MMTF encoded and optionally gzipped structure data
* @throws IOException
*/
private static byte[] toByteArray(StructureDataInterface structure, boolean compressed) throws IOException {
GenericEncoder genericEncoder = new GenericEncoder(structure);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
MessagePackSerialization serializer = new MessagePackSerialization();
serializer.serialize(genericEncoder.getMmtfEncodedStructure(), bos);
if (compressed) {
return WriterUtils.gzipCompress(bos.toByteArray());
} else {
return bos.toByteArray();
}
}
Aggregations