Class FileHelper
- java.lang.Object
-
- org.teichert.databaseexplorer.utils.FileHelper
-
public final class FileHelper extends Object
Helper-class for handling with files.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
byteArrayToFile(byte[] bytes, File outputFile)
Saves all bytes into the given file.static byte[]
byteArrayToFile(File file)
Converts the file to a byte[].static String
bytesToHex(byte[] bytes)
static File
generateUniqueFile(File file, String mimetype)
Generates a file with the given mimetype and returns this new file back.
If the passed file is null, null will be returned!static List<File>
getAllFilesRecursivly(File pFile, String suffix)
Returns all files recursivly within the pFile for the specific suffix in a list.static byte[]
getBytes(InputStream is)
Reads the inputstream into aByteArrayOutputStream
and returns the byte[] as the result.static Manifest
getManifestFile(File jarfile)
Returns the Manifest-data from the given jarfile.static String
getOnlyFilename(File file)
Return only the filename without suffix.static PrintStream
outputFile(String name)
static void
read(InputStream io, int maxRows, Consumer<String> fn)
static void
read(InputStream io, String charset, int maxRows, Consumer<String> fn)
static void
read(InputStream io, String charset, Consumer<String> fn)
static void
read(InputStream io, Consumer<String> fn)
static void
read(Reader reader, Consumer<String> fn)
static String
readFile(File f)
Reads in a file and converts it to a string.static String
readFile(File f, String charset)
Reads in a file and converts it to a string.static String
readFile(InputStream io)
Reads in a file and converts it to a string.static String
readFile(InputStream io, String charset)
Reads in a file and converts it to a string.static String
readFile(Reader reader)
Reads in a file and converts it to a string.static boolean
writeStringToFile(File file, String text)
-
-
-
Method Detail
-
readFile
public static String readFile(File f)
Reads in a file and converts it to a string.- Parameters:
f
- = file to be read in and converted.- Returns:
-
readFile
public static String readFile(InputStream io)
Reads in a file and converts it to a string.- Parameters:
io
-- Returns:
-
readFile
public static String readFile(Reader reader)
Reads in a file and converts it to a string.- Parameters:
reader
-- Returns:
-
readFile
public static String readFile(File f, String charset)
Reads in a file and converts it to a string.- Parameters:
f
- = file to be read in and converted.- Returns:
-
readFile
public static String readFile(InputStream io, String charset)
Reads in a file and converts it to a string.- Parameters:
io
-charset
-- Returns:
-
read
public static void read(InputStream io, String charset, int maxRows, Consumer<String> fn)
-
read
public static void read(InputStream io, String charset, Consumer<String> fn)
-
read
public static void read(InputStream io, int maxRows, Consumer<String> fn)
-
read
public static void read(InputStream io, Consumer<String> fn)
-
getManifestFile
public static Manifest getManifestFile(File jarfile) throws IOException
Returns the Manifest-data from the given jarfile.- Parameters:
jarfile
-- Returns:
- Throws:
IOException
-
outputFile
public static PrintStream outputFile(String name) throws FileNotFoundException
- Throws:
FileNotFoundException
-
byteArrayToFile
public static void byteArrayToFile(byte[] bytes, File outputFile)
Saves all bytes into the given file.- Parameters:
bytes
- = byte-arry to save into the saveoutputFile
- = file which will be overwritten with the given byte-arry
-
byteArrayToFile
public static byte[] byteArrayToFile(File file)
Converts the file to a byte[].- Parameters:
file
-- Returns:
-
generateUniqueFile
public static File generateUniqueFile(File file, String mimetype) throws IOException
Generates a file with the given mimetype and returns this new file back.
If the passed file is null, null will be returned!
Example:
If "File.txt" already exists then simply "File(1).txt" will be created,
if this also exists, a value "File(x).txt" is tried until one of them works.- Parameters:
file
- = File to create.mimetype
- = Mimetype of the file to create.- Returns:
- Throws:
IOException
-
getAllFilesRecursivly
public static List<File> getAllFilesRecursivly(File pFile, String suffix)
Returns all files recursivly within the pFile for the specific suffix in a list.- Parameters:
pFile
-suffix
-- Returns:
-
getOnlyFilename
public static String getOnlyFilename(File file)
Return only the filename without suffix.- Parameters:
file
-- Returns:
-
bytesToHex
public static String bytesToHex(byte[] bytes)
-
getBytes
public static byte[] getBytes(InputStream is) throws IOException
Reads the inputstream into aByteArrayOutputStream
and returns the byte[] as the result.- Parameters:
is
-- Returns:
- Throws:
IOException
-
-