Class TextFile

java.lang.Object
com.hybris.datahub.core.io.TextFile

public class TextFile extends Object
A convenience class for reading text from a file.
  • Constructor Details

    • TextFile

      public TextFile(String path)
      Instantiates a text file.
      Parameters:
      path - a path to the text file on the file system.
    • TextFile

      public TextFile(String dir, String name)
      Instantiates a text file.
      Parameters:
      dir - path to the directory, in which the file should be created.
      name - name of the file to create.
    • TextFile

      public TextFile(File file)
      Instantiates a text file.
      Parameters:
      file - a file, in which the text is stored.
  • Method Details

    • getPath

      public String getPath()
      Retrieves location of this text file.
      Returns:
      path to this text file on the file system.
    • getFilePath

      public File getFilePath()
      Retrieves location of this text file.
      Returns:
      path to this text file on the file system.
    • save

      public void save(String txt) throws IOException
      Saves text as the content of this text file
      Parameters:
      txt - a text to save in this file.
      Throws:
      IOException - when the text cannot be saved in this file.
    • append

      public TextFile append(String txt) throws IOException
      Adds text to the current content of this file.
      Parameters:
      txt - a text to add.
      Returns:
      this text file.
      Throws:
      IOException - when saving the added text fails.
    • appendLine

      public TextFile appendLine(String txt) throws IOException
      Appends text to the current content of this file and adds a new line separator at the end.
      Parameters:
      txt - a line of text to add to this file content
      Returns:
      this text file
      Throws:
      IOException - when saving the added line fails.
    • read

      public String read() throws IOException
      Reads content of this file.
      Returns:
      text saved in this file.
      Throws:
      IOException - if read failed.
    • readLine

      public String readLine(long lnum) throws IOException
      Reads specified line from this file.
      Parameters:
      lnum - number of the line to read. The line number starts from 1; there is no line 0 in a text file.
      Returns:
      text on the specified line or null, if the line number does not exist in this file.
      Throws:
      IOException - when reading the specified line fails
    • delete

      public void delete() throws IOException
      Deletes file and its content from the file system.
      Throws:
      IOException - if this file cannot be deleted.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object