/** * Creates a new {@code FileContents} instance. * * @param text the contents of the file */ public FileContents(FileText text) { fileName = text.getFile().toString(); this.text = new FileText(text); }
/** * Creates a new {@code FileContents} instance. * * @param filename name of the file * @param lines the contents of the file * @deprecated Use {@link #FileContents(FileText)} instead in order to preserve the original line * breaks where possible. */ @Deprecated public FileContents(String filename, String... lines) { fileName = filename; text = FileText.fromLines(new File(filename), Arrays.asList(lines)); }
/** * Gets the lines in the file. * * @return the lines in the file */ public String[] getLines() { return text.toLinesArray(); }
/** * Get the line from text of the file. * * @param index index of the line * @return line from text of the file */ public String getLine(int index) { return text.get(index); }
/** * Get a single line. For internal use only, as getText().get(lineNo) is just as suitable for * external use and avoids method duplication. * * @param lineNo the number of the line to get * @return the corresponding line, without terminator * @throws IndexOutOfBoundsException if lineNo is invalid */ private String line(int lineNo) { return text.get(lineNo); }