Perform the common functionality for write and writeLine methods. Since the two functions differ only in whether they write a newline character, this method contains the shared implementation. It handles the creation of the writer if necessary and writes all arguments as strings to the file. @p
(Scriptable thisObj, Object[] args, boolean eol)
| 336 | * @throws IOException if an error occurs while writing to the file |
| 337 | */ |
| 338 | private static void write0(Scriptable thisObj, Object[] args, boolean eol) throws IOException { |
| 339 | File thisFile = checkInstance(thisObj); |
| 340 | if (thisFile.reader != null) { |
| 341 | throw Context.reportRuntimeError("already reading file \"" + thisFile.name + "\""); |
| 342 | } |
| 343 | if (thisFile.writer == null) |
| 344 | thisFile.writer = |
| 345 | new BufferedWriter( |
| 346 | thisFile.file == null |
| 347 | ? new OutputStreamWriter(System.out) |
| 348 | : new FileWriter(thisFile.file)); |
| 349 | for (int i = 0; i < args.length; i++) { |
| 350 | String s = Context.toString(args[i]); |
| 351 | thisFile.writer.write(s, 0, s.length()); |
| 352 | } |
| 353 | if (eol) thisFile.writer.newLine(); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * Perform instanceof check and return the downcasted File object. |
no test coverage detected