Interface Readable
public interface Readable
The interface
Readable
provides methods for reading file contents-
Method Summary
Modifier and TypeMethodDescriptiondefault String
Reads the given file with UTF-8 encoding and returns the content as Stringdefault String
Reads the given file with the specified encoding and returns the content as StringreadAllLines
(File input) Reads all lines from the specified file into a listdefault String
readHeadLine
(String inputFile) Reads the first line from the specified filedefault byte[]
toByteArray
(File tmpFile) Reads file content into a byte arraydefault byte[]
toByteArray
(InputStream input) Gets a byte array from the givenInputStream
.default Byte[]
toObject
(byte[] byteArray) Converts a primitive byte array to a Byte array
-
Method Details
-
fromFile
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
Reads the given file with the specified encoding and returns the content as String- Parameters:
file
- the file to readencoding
- the encoding to use- Returns:
- String content from the file
- Throws:
IOException
- if an I/O exception occurs
-
readHeadLine
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 foundIOException
- if an I/O exception occurs
-
readAllLines
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
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
Gets a byte array from the givenInputStream
.- Parameters:
input
- theInputStream
- Returns:
- a byte array
- Throws:
IOException
- if an I/O exception occurs
-
toObject
Converts a primitive byte array to a Byte array- Parameters:
byteArray
- the byte array- Returns:
- Byte array
-