cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leszek Gawron <o...@wlkp.org>
Subject Re: processToStream and ConcurrentModificationException
Date Mon, 26 Apr 2004 08:02:59 GMT
On Mon, Apr 26, 2004 at 09:37:10AM +0200, Sylvain Wallez wrote:
> Leszek Gawron wrote:
> 
> >Could anybody explain why I get ConcurrentModificationException with this
> >code:
> >function test() { 
> >	var str = 
> >	"<root><guid>ZXCVXZ-ZXCZXC-#@$-ZXCVZX</guid><contractor>1</contractor><positions><position>abc</position><position>abcd</position><position>abce</position></positions></root>";
> >	var buffer = new Packages.com.mobilebox.test.OrderSaxBuffer();
> >	stringToSAX( str, buffer, "true" );
> >	
> >	var resolver = null;
> >	var source = null;
> >	var pipelineUtil = null;
> >	try {
> >		resolver = cocoon.getComponent( SourceResolver.ROLE );
> >		source = resolver.resolveURI( "context://test.xml" ); 
> >		
> >		//var s = new java.io.FileOutputStream( "abc.xml" );
> >		
> >		pipelineUtil = cocoon.createObject( 
> >		Packages.org.apache.cocoon.components.flow.util.PipelineUtil 
> >		);
> > 		pipelineUtil.processToStream( "view/test.jx", { buffer: 
> > 		buffer }, source.outputStream );
> > 		source.outputStream.close();
> > 
> >
> 
> The above lines open the ouputStream *two* times. The first time (in the 
> processToStream call), it runs ok, and a temp file is created until the 
> outputstream is closed.
> 
> The line "source.outputStream.close()" tries to *open* an outputStream 
> again, and fails because the temp file is present.
> 
> So what you should do is close the stream you write to:
>    var out = source.outputStream;
>    pipelineUtil.processToStream(..., out);
>    out.close();
> 
> You should even enclose the processToStream() with a try/finally to 
> ensure the stream is always properly closed.
Ha, I knew I messed up somewhere. These are my first day fighting sources.
Must say it's fun. Thank you for help.
	lg
-- 
            __
         | /  \ |        Leszek Gawron            //  \\
        \_\\  //_/       ouzo@wlkp.org           _\\()//_
         .'/()\'.     Phone: +48(501)720812     / //  \\ \
          \\  //  recursive: adj; see recursive  | \__/ |


Mime
View raw message