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

Method readLines

examples/src/main/java/File.java:131–142  ·  view source on GitHub ↗

Read the remaining lines in the file and return them in an array. Implements a JavaScript function that reads all remaining lines from the current position in the file and returns them as a JavaScript Array object. This is a good example of creating a new array and setting elements in that a

()

Source from the content-addressed store, hash-verified

129 * object, or if the file cannot be read
130 */
131 @JSFunction
132 public Object readLines() throws IOException {
133 List<String> list = new ArrayList<String>();
134 String s;
135 while ((s = readLine()) != null) {
136 list.add(s);
137 }
138 String[] lines = list.toArray(new String[list.size()]);
139 TopLevel scope = ScriptableObject.getTopLevelScope(getParentScope());
140 Context cx = Context.getCurrentContext();
141 return cx.newObject(scope, "Array", lines);
142 }
143
144 /**
145 * Read a single line from the file.

Callers

nothing calls this directly

Calls 8

readLineMethod · 0.95
getTopLevelScopeMethod · 0.95
getCurrentContextMethod · 0.95
newObjectMethod · 0.95
addMethod · 0.65
toArrayMethod · 0.65
sizeMethod · 0.65
getParentScopeMethod · 0.65

Tested by

no test coverage detected