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 aFile,
String aCharsetName)
Creates a new file text representation.
|
Modifier and Type | Method and Description |
---|---|
static FileText |
fromLines(File aFile,
List<String> aLines)
Compatibility conversion.
|
String |
get(int aLineNo)
Retrieves a line of the text by its number.
|
ByteBuffer |
getBytes()
Get the binary contents of the file.
|
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 aPos)
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 aFile, String aCharsetName) throws IOException
aFile
- the name of the fileaCharsetName
- the encoding to use when reading the fileNullPointerException
- if the text is nullIOException
- if the file could not be readpublic static FileText fromLines(File aFile, List<String> aLines)
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.aFile
- the name of the fileaLines
- the lines of the text, without terminatorspublic File getFile()
public Charset getCharset()
null
for a file reconstructed from its lines.public ByteBuffer getBytes() throws IOException
IOException
- if the bytes could not be read from the filepublic CharSequence getFullText()
public String[] toLinesArray()
text.toLinesArray()
is equivalent to
text.toArray(new String[text.size()])
.public LineColumn lineColumn(int aPos)
aPos
- the character position in the full textpublic String get(int aLineNo)
public int size()
size
in interface Collection<String>
size
in interface List<String>
size
in class AbstractCollection<String>
Copyright © 2001–2018. All rights reserved.