Package org.daisy.dotify.common.io
Class FileIO
- java.lang.Object
-
- org.daisy.dotify.common.io.FileIO
-
public class FileIO extends Object
Provides file IO tools.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopy(InputStream is, OutputStream os)Copies an input stream to an output stream.static voidcopyRecursive(File f, File out)Copies a folder recursively.static FilecreateTempDir()Creates a temp folder.static FilecreateTempFile()Creates a temp file.static voiddeleteRecursive(File f)Deletes a folder recursively.static longdiff(InputStream f1, InputStream f2)Compares the input streams binary.static Collection<File>listFilesRecursive(File dir, String ext)Lists files in the specified folder and sub folders having the specified extension.static URL[]toURL(File[] files)Converts an array of File objects into URL's.
-
-
-
Method Detail
-
copy
public static void copy(InputStream is, OutputStream os) throws IOException
Copies an input stream to an output stream. In Java 9 or later, useis.transferTo(OutputStream).- Parameters:
is- the input streamos- the output stream- Throws:
IOException- if IO fails
-
createTempFile
public static File createTempFile() throws IOException
Creates a temp file.- Returns:
- returns a the created file
- Throws:
IOException- if IO fails
-
createTempDir
public static File createTempDir() throws IOException
Creates a temp folder.- Returns:
- returns the created folder
- Throws:
IOException- if IO fails
-
copyRecursive
public static void copyRecursive(File f, File out)
Copies a folder recursively.- Parameters:
f- the source folderout- the destination folder
-
deleteRecursive
public static void deleteRecursive(File f)
Deletes a folder recursively.- Parameters:
f- the folder to delete
-
diff
public static long diff(InputStream f1, InputStream f2) throws IOException
Compares the input streams binary.- Parameters:
f1- the first input streamf2- the second input stream- Returns:
- returns -1 if the streams are equal, byte position where first difference occurred otherwise
- Throws:
IOException- if IO fails
-
listFilesRecursive
public static Collection<File> listFilesRecursive(File dir, String ext)
Lists files in the specified folder and sub folders having the specified extension. For non-recursive file listing, use:dir.listFiles((parent, name)->name.endsWith(ext));- Parameters:
dir- the folder to start searchext- the file extensions to find- Returns:
- returns a list of files
-
-