public final class FileText extends AbstractList<String>
This class will be passed to instances of class FileSetCheck by Checker. It implements a string list to ensure backwards compatibility, but can be extended in the future to allow more flexible, more powerful or more efficient handling of certain situations.
modCount
Constructor and Description |
---|
FileText(File file,
String charsetName)
Creates a new file text representation.
|
FileText(FileText fileText)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
static FileText |
fromLines(File file,
List<String> lines)
Compatibility conversion.
|
String |
get(int lineNo)
Retrieves a line of the text by its number.
|
Charset |
getCharset()
Get the character set which was used to read the file.
|
File |
getFile()
Get the name of the file.
|
CharSequence |
getFullText()
Retrieve the full text of the file.
|
LineColumn |
lineColumn(int pos)
Determine line and column numbers in full text.
|
int |
size()
Counts the lines of the text.
|
String[] |
toLinesArray()
Returns an array of all lines.
|
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
parallelStream, removeIf, stream
public FileText(File file, String charsetName) throws IOException
The file will be read using the specified encoding, replacing malformed input and unmappable characters with the default replacement character.
file
- the name of the filecharsetName
- the encoding to use when reading the fileNullPointerException
- if the text is nullIOException
- if the file could not be readpublic static FileText fromLines(File file, List<String> lines)
This method can be used to convert the arguments passed to
FileSetCheck.process(File,List)
to a FileText
object. If the list of lines already is a FileText, it is
returned as is. Otherwise, a new FileText is constructed by
joining the lines using line feed characters.
file
- the name of the filelines
- the lines of the text, without terminatorspublic File getFile()
public Charset getCharset()
null
for a file reconstructed from its lines.public CharSequence getFullText()
public String[] toLinesArray()
text.toLinesArray()
is equivalent to
text.toArray(new String[text.size()])
.public LineColumn lineColumn(int pos)
pos
- the character position in the full textpublic String get(int lineNo)
public int size()
size
in interface Collection<String>
size
in interface List<String>
size
in class AbstractCollection<String>
Copyright © 2001-2017. All Rights Reserved.