Hi Tobias, All,
On 15 October 2010 11:56, Tobias Girschick <[email protected]>wrote:
> Hi,
>
> We have been using the CDK IteratingMDLReader quite successful for some
> time now. But suddenly, it does not work anymore. I figured out that it
> is due to changing stuff around the cdk code...so far so good. After
> some time I noticed that the Stream I give to the IteratingMDLReader has
> changed. The working one was a java.io.PushbackInputStream, the new one
> is a org.restlet.engine.http.io.ChunkedInputStream. Both extend the
> java.io.InputStream class. Another difference I noticed, is that calling
> the available() method on the PushbackInputStream results in 1, on the
> ChunkedInputStream it results in 0. That's the fact I figured out so
> far. The code fragments around the Reader:
>
> InputStream n = r.getStream();
> // those statements made me figure out what changed:
> System.out.println("[GET2] available: "+in.available());
> System.out.println("[GET2] available: "+in.toString());
>
> IteratingMDLReader sdfreader = new IteratingMDLReader(in,
> DefaultChemObjectBuilder.getInstance());
>
> try {
> if(in != null){
> while (sdfreader.hasNext()) {
> IMolecule mol2store = (IMolecule)sdfreader.next();
> AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2store);
> CDKHueckelAromaticityDetector.detectAromaticity(mol2store);
> System.out.println("MolAtomCount: " + mol2store.getAtomCount());
> mols.add(mol2store);
> }
> }
> }catch(Exception e){
> e.printStackTrace();
> }finally{
> sdfreader.close();
> in.close();
> }
>
> The contents of the chunked stream seems to be fine...it works with
> JOELIB2 (joelib2.io.BasicReader) and it works if I write the stream to a
> file and then import it with the IteratingMDLReader.
>
> Any clues? This is quite important for us to work. At the moment we have
> a little workaround but I'd like to change that.
>
>
It turns out for the new stream you have started to use
(org.restlet.engine.http.io.ChunkedInputStream ) , the method
stream.ready() returns false, even if there are still some bytes to be
read. The stream readLine() method, however, behave correctly and will
return content if available, or will return null if no more content is
available.
Slightly modifying IteratingMDLReader will fix the IteratingMDLReader
behaviour :
------- Current ----
org.openscience.cdk.io.iterator.IteratingMDLReader
public boolean hasNext() {
if (!nextAvailableIsKnown) {
hasNext = false;
// now try to parse the next Molecule
try {
if (input.ready()) {
currentFormat = (IChemFormat)MDLFormat.getInstance();
currentLine = input.readLine();
----------- Fixed -------
public boolean hasNext() {
if (!nextAvailableIsKnown) {
hasNext = false;
// now try to parse the next Molecule
try {
if ((currentLine = input.readLine()) != null) {
currentFormat =
(IChemFormat)MDLV2000Format.getInstance();
StringBuffer buffer = new StringBuffer();
while (currentLine != null && !currentLine.equals("M
END")) {
--------
The change will not affect the current behaviour and seems to be a safer
approach in general . A similar issue is discussed here
http://stackoverflow.com/questions/754141/java-url-connection-blank-input-stream
@cdk-developers: Are there any preferences towards changing / not changing
the IteratingMDLReader as above ?
Best regards,
Nina
> best regards,
> Tobias
>
>
> --
> Dipl.-Bioinf. Tobias Girschick
>
> Technische Universität München
> Institut für Informatik
> Lehrstuhl I12 - Bioinformatik
> Bolzmannstr. 3
> 85748 Garching b. München, Germany
>
> --
> Tobias Girschick
> mailto: [email protected]
>
>
> ------------------------------------------------------------------------------
> Download new Adobe(R) Flash(R) Builder(TM) 4
> The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
> Flex(R) Builder(TM)) enable the development of rich applications that run
> across multiple browsers and platforms. Download your free trials today!
> http://p.sf.net/sfu/adobe-dev2dev
> _______________________________________________
> Cdk-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cdk-user
>
>
------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user