ByteArrayOutputStream corrupted, MolExporter involved

User e469f67125

23-04-2008 18:59:16

The attached test program writes a smiles using MolExporter in two ways, to a file (works fine), and to a java.io.ObjectOutputStream(java.io.ByteArrayOutputStream). The ByteArrayOutputStream is written to stdout using ByteArrayOutputStream.writeTo(System.out). The problem is that stdout is different than the output file. There seems to be some binary data pre-pended to the smiles.





I know this is a trivial example and this program could be fixed in many ways. But the real problem comes when I try a binary output format such as PNG and a ByteArray is necessary.





Thanks in advance for any help, and sorry if I'm missing something obvious.








$ java test_stdout > zz.smi


$ ls -l z.smi zz.smi


-rw-r--r-- 1 jjyang jjyang 18 Apr 23 12:55 z.smi


-rw-r--r-- 1 jjyang jjyang 24 Apr 23 12:55 zz.smi


$ cat z.smi


NCCc1ccc(O)c(O)c1


$ cat zz.smi


��wNCCc1ccc(O)c(O)c1











JChem version: 5_0_02_1


JDK: 1.6.0_03, linux 32bit

ChemAxon 7c2d26e5cf

25-04-2008 14:26:17

Please read the (Sun) documentation of java.io.ObjectOutputStream.


ObjectOutputStream inserts meta-data into the stream by instantiation.


This is independent from Marvin. Marvin writes only the molecule string into the stream.


The following code sniplet demonstrates what happens when you create a new ObjectOutputStream.


Code:
ByteArrayOutputStream obuff = new ByteArrayOutputStream();


ObjectOutputStream oos = new ObjectOutputStream(obuff);


oos.close();


obuff.writeTo(System.out);