private static void write0(Scriptable thisObj, Object[] args, boolean eol)
        throws IOException
    {
        File thisFile = checkInstance(thisObj);
        if (thisFile.reader != null) {
            throw Context.reportRuntimeError("already writing file \""
                                             + thisFile.name
                                             + "\"");
        }
        if (thisFile.writer == null)
            thisFile.writer = new BufferedWriter(
                thisFile.file == null ? new OutputStreamWriter(System.out)
                                      : new FileWriter(thisFile.file));
        for (int i=0; i < args.length; i++) {
            String s = Context.toString(args[i]);
            thisFile.writer.write(s, 0, s.length());
        }
        if (eol)
            thisFile.writer.newLine();
    }
private static void write0 ( Scriptable thisObj , Object [ ] args , boolean eol ) throws IOException { File thisFile = checkInstance ( thisObj ) ; if ( thisFile . reader != null ) { throw Context . reportRuntimeError ( "already writing file \"" + thisFile . name + "\"" ) ; } if ( thisFile . writer == null ) thisFile . writer = new BufferedWriter ( thisFile . file == null ? new OutputStreamWriter ( System . out ) : new FileWriter ( thisFile . file ) ) ; for ( int i = 0 ; i < args . length ; i ++ ) { String s = Context . toString ( args [ i ] ) ; thisFile . writer . write ( s , 0 , s . length ( ) ) ; } if ( eol ) thisFile . writer . newLine ( ) ; }
Perform the guts of write and writeLine.

Since the two functions differ only in whether they write a
newline character, move the code into a common subroutine.