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
()
| 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. |
nothing calls this directly
no test coverage detected