Bug 10785 - fillbuf() in InputEntity blocks on Parsing characacters from a Stream.
Summary: fillbuf() in InputEntity blocks on Parsing characacters from a Stream.
Status: NEW
Alias: None
Product: Crimson
Classification: Unclassified
Component: other (show other bugs)
Version: 1.1.3
Hardware: All All
: P3 blocker (vote)
Target Milestone: ---
Assignee: Edwin Goei
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-14 13:47 UTC by Alfonso S
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alfonso S 2002-07-14 13:47:50 UTC
When parsing from a Stream the fillbuf method is called after the last element 
of the document (parsing goes fine till this point). Then it tries to read 8k 
of data (the length of the buffer), this obviosly block the process when using 
streams.

	boolean	extra = (finish > 0) && (start > 0);
	int	len;

	if (extra)		// extra pushback
	    start--;
	len = finish - start;

	System.arraycopy (buf, start, buf, 0, len);
	start = 0;
	finish = len;

	try {
	    len = buf.length - len;
	    len = reader.read (buf, finish, len); // BLOCKS
	}
I have tried to fix it substituting the try block with: 
        try{
	  len = buf.length - len;
	  int appended = 0;

	  while( reader.ready() && finish<=buf.length && appended<=len ){
	    
	    int val = reader.read();
	    if( val == -1 ) close();
	    else{
    	      char c = (char)val;
    	      if( Character.isDefined( c ) ){
        	buf[finish++] = c;
        	appended++;
    	      }
	    }
	  }
	len = appended;
        }
Which fires an exception but at least doesn't block.
I am sure that you vcan find a much better solution though :-)