Package io.github.astrapi69.file.read
Class ReadFileExtensions
- java.lang.Object
-
- io.github.astrapi69.file.read.ReadFileExtensions
-
public final class ReadFileExtensions extends java.lang.Object
The classReadFileExtensions
helps you reading files.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
countAllLines(java.io.File fileToCountTheLines)
Count all lines from the given filestatic java.lang.Byte[]
getFilecontentAsByteObjectArray(java.io.File tmpFile)
Get a Byte array from the given file.static java.lang.String
inputStream2String(java.io.InputStream inputStream)
The Method inputStream2String() reads the data from the InputStream into a String.static java.lang.String
inputStream2String(java.io.InputStream inputStream, java.nio.charset.Charset encoding)
The Method inputStream2String() reads the data from the InputStream into a String.static java.io.Reader
openFileReader(java.lang.String fileName)
The Method openFileReader() opens a BufferedReader from the given file.static java.lang.String
reader2String(java.io.Reader reader)
The Method reader2String() reads the data from the Reader into a String.
Note: Reader will not be closed.static byte[]
readFileToBytearray(java.io.File file)
Get a byte array from the given file.static java.lang.String
readFromFile(java.io.File file)
The Method readFromFile() reads the filecontent to a String.static java.lang.String
readFromFile(java.io.File file, java.nio.charset.Charset encoding)
Read from file.static java.lang.String
readHeadLine(java.lang.String inputFile)
The Method readHeadLine() opens the File and reads the first line from the file.static java.util.List<java.lang.String>
readLinesInList(java.io.File input)
Reads every line from the File and puts them to the List.static java.util.List<java.lang.String>
readLinesInList(java.io.File input, boolean trim)
Reads every line from the File and puts them to the List.static java.util.List<java.lang.String>
readLinesInList(java.io.File input, java.nio.charset.Charset encoding)
Reads every line from the File and puts them to the List.static java.util.List<java.lang.String>
readLinesInList(java.io.File input, java.nio.charset.Charset encoding, boolean trim)
Reads every line from the File and puts them to the List.static java.util.List<java.lang.String>
readLinesInList(java.io.InputStream input)
Reads every line from the given InputStream and puts them to the List.static java.util.List<java.lang.String>
readLinesInList(java.io.InputStream input, boolean trim)
Reads every line from the given InputStream and puts them to the List.static java.util.List<java.lang.String>
readLinesInList(java.io.InputStream input, java.nio.charset.Charset encoding, boolean trim)
Reads every line from the given InputStream and puts them to the List.static java.util.Properties
readPropertiesFromFile(java.lang.String filename)
The Method readFromFile(String) reads from the properties-file all Properties and saves them into a Properties-Object.static byte[]
toByteArray(java.io.File tmpFile)
Get a byte array from the given file.static byte[]
toByteArray(java.io.InputStream input)
Get a byte array from the givenInputStream
.
-
-
-
Method Detail
-
getFilecontentAsByteObjectArray
public static java.lang.Byte[] getFilecontentAsByteObjectArray(java.io.File tmpFile) throws java.io.IOException
Get a Byte array from the given file.- Parameters:
tmpFile
- the tmp file- Returns:
- the filecontent as Byte array object.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
inputStream2String
public static java.lang.String inputStream2String(java.io.InputStream inputStream) throws java.io.IOException
The Method inputStream2String() reads the data from the InputStream into a String.- Parameters:
inputStream
- The InputStream from where we read.- Returns:
- The String that we read from the InputStream.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
inputStream2String
public static java.lang.String inputStream2String(java.io.InputStream inputStream, java.nio.charset.Charset encoding) throws java.io.IOException
The Method inputStream2String() reads the data from the InputStream into a String.- Parameters:
inputStream
- The InputStream from where we read.encoding
- the encoding- Returns:
- The String that we read from the InputStream.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
openFileReader
public static java.io.Reader openFileReader(java.lang.String fileName) throws java.io.IOException
The Method openFileReader() opens a BufferedReader from the given file.- Parameters:
fileName
- The file from where to read.- Returns:
- The opened BufferedReader from the specified file.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
reader2String
public static java.lang.String reader2String(java.io.Reader reader) throws java.io.IOException
The Method reader2String() reads the data from the Reader into a String.
Note: Reader will not be closed.- Parameters:
reader
- The Reader from where we read.- Returns:
- The String that we read from the Reader.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
readFileToBytearray
public static byte[] readFileToBytearray(java.io.File file) throws java.io.IOException
Get a byte array from the given file.- Parameters:
file
- The file.- Returns:
- Returns a byte array or null.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
readFromFile
public static java.lang.String readFromFile(java.io.File file) throws java.io.IOException
The Method readFromFile() reads the filecontent to a String.- Parameters:
file
- The File to read to a String.- Returns:
- The String from the File.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
readFromFile
public static java.lang.String readFromFile(java.io.File file, java.nio.charset.Charset encoding) throws java.io.IOException
Read from file.- Parameters:
file
- the fileencoding
- the encoding- Returns:
- the string
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
readHeadLine
public static java.lang.String readHeadLine(java.lang.String inputFile) throws java.io.FileNotFoundException, java.io.IOException
The Method readHeadLine() opens the File and reads the first line from the file.- Parameters:
inputFile
- The Path to the File and name from the file from where we read.- Returns:
- The first line from the file.
- Throws:
java.io.FileNotFoundException
- is thrown if the given file is not found.java.io.IOException
- Signals that an I/O exception has occurred.
-
readLinesInList
public static java.util.List<java.lang.String> readLinesInList(java.io.File input) throws java.io.FileNotFoundException, java.io.IOException
Reads every line from the File and puts them to the List.- Parameters:
input
- The File from where the input comes.- Returns:
- The List with all lines from the file.
- Throws:
java.io.FileNotFoundException
- is thrown if the given file is not found.java.io.IOException
- Signals that an I/O exception has occurred.
-
readLinesInList
public static java.util.List<java.lang.String> readLinesInList(java.io.File input, boolean trim) throws java.io.FileNotFoundException, java.io.IOException
Reads every line from the File and puts them to the List.- Parameters:
input
- The File from where the input comes.trim
- the flag trim if the lines shell be trimed.- Returns:
- The List with all lines from the file.
- Throws:
java.io.FileNotFoundException
- is thrown if the given file is not found.java.io.IOException
- Signals that an I/O exception has occurred.
-
readLinesInList
public static java.util.List<java.lang.String> readLinesInList(java.io.File input, java.nio.charset.Charset encoding) throws java.io.FileNotFoundException, java.io.IOException
Reads every line from the File and puts them to the List.- Parameters:
input
- The File from where the input comes.encoding
- the encoding- Returns:
- The List with all lines from the file.
- Throws:
java.io.FileNotFoundException
- is thrown if the given file is not found.java.io.IOException
- When a io-problem occurs.
-
readLinesInList
public static java.util.List<java.lang.String> readLinesInList(java.io.File input, java.nio.charset.Charset encoding, boolean trim) throws java.io.FileNotFoundException, java.io.IOException
Reads every line from the File and puts them to the List.- Parameters:
input
- The File from where the input comes.encoding
- the charset for readtrim
- the flag trim if the lines shell be trimed.- Returns:
- The List with all lines from the file.
- Throws:
java.io.FileNotFoundException
- is thrown if the given file is not found.java.io.IOException
- When a io-problem occurs.
-
readLinesInList
public static java.util.List<java.lang.String> readLinesInList(java.io.InputStream input) throws java.io.IOException
Reads every line from the given InputStream and puts them to the List.- Parameters:
input
- The InputStream from where the input comes.- Returns:
- The List with all lines from the file.
- Throws:
java.io.IOException
- When a io-problem occurs.
-
readLinesInList
public static java.util.List<java.lang.String> readLinesInList(java.io.InputStream input, boolean trim) throws java.io.IOException
Reads every line from the given InputStream and puts them to the List.- Parameters:
input
- The InputStream from where the input comes.trim
- the flag trim if the lines shell be trimed.- Returns:
- The List with all lines from the file.
- Throws:
java.io.IOException
- When a io-problem occurs.
-
readLinesInList
public static java.util.List<java.lang.String> readLinesInList(java.io.InputStream input, java.nio.charset.Charset encoding, boolean trim) throws java.io.IOException
Reads every line from the given InputStream and puts them to the List.- Parameters:
input
- The InputStream from where the input comes.encoding
- the charset for readtrim
- the flag trim if the lines shell be trimed.- Returns:
- The List with all lines from the file.
- Throws:
java.io.IOException
- When a io-problem occurs.
-
readPropertiesFromFile
public static java.util.Properties readPropertiesFromFile(java.lang.String filename) throws java.io.IOException
The Method readFromFile(String) reads from the properties-file all Properties and saves them into a Properties-Object.- Parameters:
filename
- The Filename from the Properties-file.- Returns:
- The Properties or null if an error occurs.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
toByteArray
public static byte[] toByteArray(java.io.File tmpFile) throws java.io.IOException
Get a byte array from the given file.- Parameters:
tmpFile
- The file.- Returns:
- Returns a byte array or null.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
toByteArray
public static byte[] toByteArray(java.io.InputStream input) throws java.io.IOException
Get a byte array from the givenInputStream
.- Parameters:
input
- TheInputStream
.- Returns:
- the a byte array.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.java.lang.NullPointerException
- if the input is null
-
countAllLines
public static long countAllLines(java.io.File fileToCountTheLines) throws java.io.IOException
Count all lines from the given file- Parameters:
fileToCountTheLines
- The File to count the lines- Returns:
- the number of the lines from the given file
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
-