edu.northwestern.at.utils

## Class TextFile

- java.lang.Object
- - edu.northwestern.at.utils.TextFile

-     public class TextFile
      extends java.lang.Object

  TextFile reads a text file into an array of strings.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.io.File` | `textFile` The text file.
    `protected java.lang.String` | `textFileEncoding` The text file encoding.
    `protected java.lang.String[]` | `textFileLines` The text of the data file, split into lines.
    `protected boolean` | `textFileLoaded` True if file loaded OK.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TextFile(java.io.File textFile)` Create text file object from local file.
    `TextFile(java.io.File textFile, java.lang.String encoding)` Create text file object from file with specified encoding.
    `TextFile(java.io.InputStream inputStream)` Create data file object from input stream.
    `TextFile(java.io.InputStream inputStream, java.lang.String encoding)` Create data file object from input stream.
    `TextFile(java.lang.String textFileName)` Create text file object from named file.
    `TextFile(java.lang.String textFileName, java.lang.String encoding)` Create text file object from named file with specified encoding.
    `TextFile(java.net.URL url, java.lang.String encoding)` Create data file object from URL.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `openFile(java.io.File inputFile)` Read local file into array of strings.
    `protected void` | `openInputStream(java.io.InputStream inputStream)` Read stream into array of strings.
    `int` | `size()` Return number of lines in the data file.
    `boolean` | `textLoaded()` Did text load OK?
    `java.lang.String[]` | `toArray()` Return file contents as a string array.
    `java.lang.String` | `toString()` Return file contents as a string.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### textFile

          protected java.io.File textFile

      The text file. May be null if file read from a stream.

    - #### textFileEncoding

          protected java.lang.String textFileEncoding

      The text file encoding. Defaults to utf-8.

    - #### textFileLines

          protected java.lang.String[] textFileLines

      The text of the data file, split into lines.

    - #### textFileLoaded

          protected boolean textFileLoaded

      True if file loaded OK.

  - ### Constructor Detail

    - #### TextFile

          public TextFile(java.io.File textFile,
                  java.lang.String encoding)

      Create text file object from file with specified encoding.
      Parameters:
        `textFile` - Text file.
        `encoding` - Text file encoding (utf-8, 8859_1, etc.).

    - #### TextFile

          public TextFile(java.lang.String textFileName,
                  java.lang.String encoding)

      Create text file object from named file with specified encoding.
      Parameters:
        `textFileName` - The data file name.
        `encoding` - Text file encoding (utf-8, 8859_1, etc.).

    - #### TextFile

          public TextFile(java.lang.String textFileName)

      Create text file object from named file.
      Parameters:
        `textFileName` - The data file name.

    - #### TextFile

          public TextFile(java.io.File textFile)

      Create text file object from local file.
      Parameters:
        `textFile` - The data file.

    - #### TextFile

          public TextFile(java.io.InputStream inputStream,
                  java.lang.String encoding)

      Create data file object from input stream.
      Parameters:
        `inputStream` - The input stream for the data file.
        `encoding` - Text file encoding (utf-8, 8859_1, etc.).

    - #### TextFile

          public TextFile(java.net.URL url,
                  java.lang.String encoding)

      Create data file object from URL.
      Parameters:
        `url` - The input URL for the data file.
        `encoding` - Text file encoding (utf-8, 8859_1, etc.).

    - #### TextFile

          public TextFile(java.io.InputStream inputStream)

      Create data file object from input stream.
      Parameters:
        `inputStream` - The input stream for the data file.

  - ### Method Detail

    - #### openFile

          protected void openFile(java.io.File inputFile)

      Read local file into array of strings.
      Parameters:
        `inputFile` - The input file. The file is opened using the urf-8 character set.

    - #### openInputStream

          protected void openInputStream(java.io.InputStream inputStream)

      Read stream into array of strings.
      Parameters:
        `inputStream` - The InputStream for the file.

    - #### size

          public int size()

      Return number of lines in the data file.
      Returns:
        Number of lines in the file.

    - #### textLoaded

          public boolean textLoaded()

      Did text load OK?
      Returns:
        true if text file loaded OK.

    - #### toArray

          public java.lang.String[] toArray()

      Return file contents as a string array.
      Returns:
        File contents as a string array.

    - #### toString

          public java.lang.String toString()

      Return file contents as a string.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        File contents as a string.

        Each line of the data file is separated by the platform line separator character in the returned string.