MCPcopy Create free account
hub / github.com/mozilla/rhino / write0

Method write0

examples/src/main/java/File.java:338–354  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 2

writeMethod · 0.95
writeLineMethod · 0.95

Calls 5

checkInstanceMethod · 0.95
reportRuntimeErrorMethod · 0.95
toStringMethod · 0.95
writeMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected