Skip to content

Commit 0b42061

Browse files
committed
Write MMTF to an OutputStream
1 parent 566d41c commit 0b42061

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

  • biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf

biojava-structure/src/main/java/org/biojava/nbio/structure/io/mmtf/MmtfActions.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.biojava.nbio.structure.io.mmtf;
22

3+
import java.io.ByteArrayOutputStream;
34
import java.io.IOException;
5+
import java.io.OutputStream;
46
import java.nio.file.Path;
57

68
import org.biojava.nbio.structure.Structure;
@@ -46,6 +48,24 @@ public static void writeToFile(Structure structure, Path path) throws IOExceptio
4648
// Now write this data to file
4749
WriterUtils.writeDataToFile(writerToEncoder, path);
4850
}
51+
52+
/**
53+
* Write a Structure object to an {@link OutputStream}
54+
* @param structure the Structure to write
55+
* @return the {@link OutputStream} of the MMTF structure
56+
* @throws IOException an error transferring the byte[]
57+
*/
58+
public static OutputStream writeToOutputStream(Structure structure) throws IOException{
59+
// Set up this writer
60+
AdapterToStructureData writerToEncoder = new AdapterToStructureData();
61+
// Get the writer - this is what people implement
62+
new MmtfStructureWriter(structure, writerToEncoder);
63+
// Now write this data to file
64+
byte[] outputBytes = WriterUtils.getDataAsByteArr(writerToEncoder);
65+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(outputBytes.length);
66+
byteArrayOutputStream.write(outputBytes,0,outputBytes.length);
67+
return byteArrayOutputStream;
68+
}
4969

5070

5171
/**

0 commit comments

Comments
 (0)