public interface Readable
The interface Readable provides methods for reading file contents
  • Method Summary

    Modifier and Type
    Method
    Description
    default String
    fromFile(File file)
    Reads the given file with UTF-8 encoding and returns the content as String
    default String
    fromFile(File file, Charset encoding)
    Reads the given file with the specified encoding and returns the content as String
    default List<String>
    Reads all lines from the specified file into a list
    default String
    readHeadLine(String inputFile)
    Reads the first line from the specified file
    default byte[]
    toByteArray(File tmpFile)
    Reads file content into a byte array
    default byte[]
    Gets a byte array from the given InputStream.
    default Byte[]
    toObject(byte[] byteArray)
    Converts a primitive byte array to a Byte array
  • Method Details

    • fromFile

      default String fromFile(File file) throws IOException
      Reads the given file with UTF-8 encoding and returns the content as String
      Parameters:
      file - the file to read
      Returns:
      String content from the file
      Throws:
      IOException - if an I/O exception occurs
    • fromFile

      default String fromFile(File file, Charset encoding) throws IOException
      Reads the given file with the specified encoding and returns the content as String
      Parameters:
      file - the file to read
      encoding - the encoding to use
      Returns:
      String content from the file
      Throws:
      IOException - if an I/O exception occurs
    • readHeadLine

      default String readHeadLine(String inputFile) throws FileNotFoundException, IOException
      Reads the first line from the specified file
      Parameters:
      inputFile - the file path
      Returns:
      first line from the file
      Throws:
      FileNotFoundException - if the file is not found
      IOException - if an I/O exception occurs
    • readAllLines

      default List<String> readAllLines(File input) throws IOException
      Reads all lines from the specified file into a list
      Parameters:
      input - the file to read
      Returns:
      list of lines from the file
      Throws:
      IOException - if an I/O exception occurs
    • toByteArray

      default byte[] toByteArray(File tmpFile) throws IOException
      Reads file content into a byte array
      Parameters:
      tmpFile - the file to read
      Returns:
      byte array of file content or null
      Throws:
      IOException - if an I/O exception occurs
    • toByteArray

      default byte[] toByteArray(InputStream input) throws IOException
      Gets a byte array from the given InputStream.
      Parameters:
      input - the InputStream
      Returns:
      a byte array
      Throws:
      IOException - if an I/O exception occurs
    • toObject

      default Byte[] toObject(byte[] byteArray)
      Converts a primitive byte array to a Byte array
      Parameters:
      byteArray - the byte array
      Returns:
      Byte array