Class FileText


  • public final class FileText
    extends java.lang.Object
    Represents the text contents of a file of arbitrary plain text type.

    This class will be passed to instances of class FileSetCheck by Checker.

    • Constructor Summary

      Constructors 
      Constructor Description
      FileText​(FileText fileText)
      Copy constructor.
      FileText​(java.io.File file, java.lang.String charsetName)
      Creates a new file text representation.
      FileText​(java.io.File file, java.util.List<java.lang.String> lines)
      Compatibility constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String get​(int lineNo)
      Retrieves a line of the text by its number.
      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 pos)
      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.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileText

        public FileText​(FileText fileText)
        Copy constructor.
        Parameters:
        fileText - to make copy of
      • FileText

        public FileText​(java.io.File file,
                        java.util.List<java.lang.String> lines)
        Compatibility constructor.

        This constructor reconstructs the text of the file by joining lines with linefeed characters. This process does not restore the original line terminators and should therefore be avoided.

        Parameters:
        file - the name of the file
        lines - the lines of the text, without terminators
        Throws:
        java.lang.NullPointerException - if the lines array is null
      • FileText

        public FileText​(java.io.File file,
                        java.lang.String charsetName)
                 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:
        file - the name of the file
        charsetName - 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

      • get

        public java.lang.String get​(int lineNo)
        Retrieves a line of the text by its number. The returned line will not contain a trailing terminator.
        Parameters:
        lineNo - the number of the line to get, starting at zero
        Returns:
        the line with the given number
      • 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
      • 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 pos)
        Determine line and column numbers in full text.
        Parameters:
        pos - the character position in the full text
        Returns:
        the line and column numbers of this character
      • size

        public int size()
        Counts the lines of the text.
        Returns:
        the number of lines in the text