Search in sources :

Example 1 with GenericEncoder

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();
    }
}
Also used : MessagePackSerialization(org.rcsb.mmtf.serialization.MessagePackSerialization) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GenericEncoder(org.rcsb.mmtf.encoder.GenericEncoder)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 GenericEncoder (org.rcsb.mmtf.encoder.GenericEncoder)1 MessagePackSerialization (org.rcsb.mmtf.serialization.MessagePackSerialization)1