com.puppycrawl.tools.checkstyle.api
Class FileText

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<java.lang.String>
          extended by com.puppycrawl.tools.checkstyle.api.FileText
All Implemented Interfaces:
java.lang.Iterable<java.lang.String>, java.util.Collection<java.lang.String>, java.util.List<java.lang.String>

public final class FileText
extends java.util.AbstractList<java.lang.String>

Represents the text contents of a file of arbitrary plain text type.

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.

Author:
Martin von Gagern

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
FileText(java.io.File aFile, java.lang.String aCharsetName)
          Creates a new file text representation.
 
Method Summary
static FileText fromLines(java.io.File aFile, java.util.List<java.lang.String> aLines)
          Compatibility conversion.
 java.lang.String get(int aLineNo)
          Retrieves a line of the text by its number.
 java.nio.ByteBuffer getBytes()
          Get the binary contents of the file.
 java.nio.charset.Charset getCharset()
          Get the character set which was used to read the file.
 java.io.File getFile()
          Get the name of the file.
 java.lang.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.
 java.lang.String[] toLinesArray()
          Returns an array of all lines.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

FileText

public FileText(java.io.File aFile,
                java.lang.String aCharsetName)
         throws java.io.IOException
Creates a new file text representation. The file will be read using the specified encoding, replacing malformed input and unmappable characters with the default replacement character.

Parameters:
aFile - the name of the file
aCharsetName - the encoding to use when reading the file
Throws:
java.lang.NullPointerException - if the text is null
java.io.IOException - if the file could not be read
Method Detail

fromLines

public static FileText fromLines(java.io.File aFile,
                                 java.util.List<java.lang.String> aLines)
Compatibility conversion. 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.

Parameters:
aFile - the name of the file
aLines - the lines of the text, without terminators
Returns:
an object representing the denoted text file

getFile

public java.io.File getFile()
Get the name of the file.

Returns:
an object containing the name of the file

getCharset

public java.nio.charset.Charset getCharset()
Get the character set which was used to read the file. Will be null for a file reconstructed from its lines.

Returns:
the charset used when the file was read

getBytes

public java.nio.ByteBuffer getBytes()
                             throws java.io.IOException
Get the binary contents of the file. The returned object must not be modified.

Returns:
a buffer containing the bytes making up the file
Throws:
java.io.IOException - if the bytes could not be read from the file

getFullText

public java.lang.CharSequence getFullText()
Retrieve the full text of the file.

Returns:
the full text of the file

toLinesArray

public java.lang.String[] toLinesArray()
Returns an array of all lines. text.toLinesArray() is equivalent to text.toArray(new String[text.size()]).

Returns:
an array of all lines of the text

lineColumn

public LineColumn lineColumn(int aPos)
Determine line and column numbers in full text.

Parameters:
aPos - the character position in the full text
Returns:
the line and column numbers of this character

get

public java.lang.String get(int aLineNo)
Retrieves a line of the text by its number. The returned line will not contain a trailing terminator.

Specified by:
get in interface java.util.List<java.lang.String>
Specified by:
get in class java.util.AbstractList<java.lang.String>
Parameters:
aLineNo - the number of the line to get, starting at zero
Returns:
the line with the given number

size

public int size()
Counts the lines of the text.

Specified by:
size in interface java.util.Collection<java.lang.String>
Specified by:
size in interface java.util.List<java.lang.String>
Specified by:
size in class java.util.AbstractCollection<java.lang.String>
Returns:
the number of lines in the text


Copyright © 2001-2010. All Rights Reserved.