|
1 | 1 | package org.biojava.nbio.structure.io.mmtf; |
2 | 2 |
|
| 3 | +import java.io.ByteArrayOutputStream; |
3 | 4 | import java.io.IOException; |
| 5 | +import java.io.OutputStream; |
4 | 6 | import java.nio.file.Path; |
5 | 7 |
|
6 | 8 | import org.biojava.nbio.structure.Structure; |
@@ -46,6 +48,24 @@ public static void writeToFile(Structure structure, Path path) throws IOExceptio |
46 | 48 | // Now write this data to file |
47 | 49 | WriterUtils.writeDataToFile(writerToEncoder, path); |
48 | 50 | } |
| 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 | + } |
49 | 69 |
|
50 | 70 |
|
51 | 71 | /** |
|
0 commit comments