Russel Winder | 1 Dec 2004 17:02
Picon
Gravatar

Re: Is this a buffering problem?


I have been hunting around in the Groovy source code but as I do not
really know how the Groovy system works I may have got things wrong.

Anyway, the line:

	javaProcess.out.println("3")

clearly compiles but an OutputStream does not have a println method so I
must assume that the Groovy system makes us of the method:

org.codehaus.groovy.runtime.DefaultGroovyMethods.println(Object,Object))

which is defined to write to the standard output which is consistent
with the observed behaviour.  The problem then becomes why doesn't:

	javaProcess.out.write("3") ;

work and that is obvious OutputStream doesn't have a suitable method we
really need to use a OutputStreamWriter.  So I tried:

#! /usr/bin/env groovy

import java.io.OutputStreamWriter 

process = "tee flob".execute()

outputWriter = new OutputStreamWriter (process.out)
outputWriter.write("13\n")
outputWriter.flush()

and this works as expected.  NB  The flush is critical here as Writers
have some buffering.

So the summary is that the originally reported behaviour is explainable
but is not the behaviour that should be happening?

--

-- 
Russel.
=============================================
Dr Russel Winder         +44 20 7585 2200
41 Buckmaster Road       +44 7770 465 077
London SW11 1EN, UK      russel@...


Gmane