|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.knime.core.util.FileUtil
public final class FileUtil
Utility class to do some basic file handling that is not available through java API. This includes copying of files and deleting entire directories. These methods are mainly used for the load/save of the workflow.
Nested Class Summary | |
---|---|
static interface |
FileUtil.ZipFileFilter
Passed to the zipDir(File, Collection, int, ZipFileFilter,
ExecutionMonitor)
method to exclude certain files from being archived and added to the zip
file.A default implementation accepting all files is ZIP_INCLUDEALL_FILTER |
Field Summary | |
---|---|
static FileUtil.ZipFileFilter |
ZIP_INCLUDEALL_FILTER
A filter that causes all files to be included in the zip archive. |
Method Summary | |
---|---|
static boolean |
chmod(File f,
Boolean readable,
Boolean writable,
Boolean executable,
boolean ownerOnly)
Sets the permissions on a given file or directory. |
static void |
copy(File file,
File destination)
Copies a file. |
static void |
copy(File file,
File destination,
ExecutionMonitor exec)
Copies a file. |
static void |
copy(InputStream input,
OutputStream destination)
Copies the bytes as read from input to the output stream
destination . |
static void |
copy(Reader source,
Writer destination)
Copies the chars as read from source to the writer
destination . |
static void |
copyDir(File sourceDir,
File targetDir)
Copies the given source (either a file or a directory) into the given source. |
static File |
createTempDir(String prefix)
Creates a temporary directory that is automatically deleted when the JVM shuts down. |
static File |
createTempDir(String prefix,
File dir)
Creates a temporary directory that is automatically deleted when the JVM shuts down. |
static boolean |
deleteRecursively(File dir)
Deletes a given directory recursively. |
static void |
unzip(File zipFile,
File destDir)
Extracts the contents of the given ZIP file into the destination directory. |
static void |
unzip(ZipInputStream zipStream,
File dir,
int stripLevel)
Stores the content of the zip stream in the specified directory. |
static boolean |
zipDir(File zipFile,
Collection<File> includeList,
int compressionLevel,
FileUtil.ZipFileFilter filter,
ExecutionMonitor exec)
Packs all files and directories passed in the includeList into a zip file. |
static boolean |
zipDir(File zipFile,
File rootDir,
int compressionLevel)
Recursively packs all the the files and directories beneath the rootDir into a zip file. |
static boolean |
zipDir(File zipFile,
File rootDir,
int compressionLevel,
FileUtil.ZipFileFilter filter,
ExecutionMonitor exec)
Recursively packs all the the files and directories beneath the rootDir into a zip file. |
static boolean |
zipDir(ZipOutputStream zout,
Collection<File> includeList,
FileUtil.ZipFileFilter filter,
ExecutionMonitor exec)
Packs all files and directories passed in the includeList into a zip stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final FileUtil.ZipFileFilter ZIP_INCLUDEALL_FILTER
Method Detail |
---|
public static void copy(File file, File destination, ExecutionMonitor exec) throws IOException, CanceledExecutionException
file
- The file to copy.destination
- The destination file, fully qualified (do not provide
a directory).exec
- The execution monitor for progress information.
CanceledExecutionException
- If canceled. The destination file will
be deleted.
IOException
- If that fail for any reason.public static void copyDir(File sourceDir, File targetDir) throws IOException
sourceDir
- contains all source file and directories to be copiedtargetDir
- target file (created or replaced) with the given source
file structure
IOException
- if the source does not exist or the source could not
be copied due to file permissionspublic static void copy(InputStream input, OutputStream destination) throws IOException
input
to the output stream
destination
. Neither input
nor
destination
get closed at the end!
input
- To read fromdestination
- To write to
IOException
- If that fails for any reason.
NullPointerException
- If any argument is null
.public static void copy(Reader source, Writer destination) throws IOException
source
to the writer
destination
. Neither input
nor
destination
get closed at the end!
source
- To read fromdestination
- To write to
IOException
- If that fails for any reason.
NullPointerException
- If any argument is null
.public static void copy(File file, File destination) throws IOException
file
- The file to copy.destination
- The destination file, fully qualified (do not provide
a directory).
IOException
- If that fail for any reason.public static boolean deleteRecursively(File dir)
dir
- The directory or file to delete.
public static boolean zipDir(File zipFile, Collection<File> includeList, int compressionLevel, FileUtil.ZipFileFilter filter, ExecutionMonitor exec) throws IOException, CanceledExecutionException
zipFile
- the zip file that should be created. If it exists it will
be overwritten.includeList
- list of files or directories to add to the zip
archive. Directories will be added with their content
(recursively). Files are placed in the root of the archive
(i.e. their path is not preserved). If entries have the same
(simple) name, an I/O Exception is thrown.compressionLevel
- the desired compression level, see
ZipOutputStream.setLevel(int)
filter
- each file (and directory) contained is only included in the
zip archive if it is accepted by the filter. If a directory is
not accepted, it entire content is excluded from the zip. Must
not be null.exec
- receives progress messages and is checked for cancel
requests. Optional, can be null.
true
if all files and dirs accepted by the filter
are included, false
if an error occurs reading a
file, if a directory is unreadable.
CanceledExecutionException
- if the operation was canceled through
the exec
IOException
- if an I/O error occurs when writing the zip file, or
if two files or directories in the include list have the same
(simple) name.public static boolean zipDir(ZipOutputStream zout, Collection<File> includeList, FileUtil.ZipFileFilter filter, ExecutionMonitor exec) throws IOException, CanceledExecutionException
zout
- a zipped output stream. Zip entries for each file are added
to the stream. The compression level is not changed by this
method. The stream remains open after the method returns!includeList
- list of files or directories to add to the zip
archive. Directories will be added with their content
(recursively). Files are placed in the root of the archive
(i.e. their path is not preserved).filter
- each file (and directory) contained is only included in the
zip archive if it is accepted by the filter. If a directory is
not accepted, it entire content is excluded from the zip. Must
not be null.exec
- receives progress messages and is checked for cancel
requests. Optional, can be null.
true
if all files and dirs accepted by the filter
are included, false
if an error occurs reading a
file in a directory, if a directory is unreadable.
CanceledExecutionException
- if the operation was canceled through
the exec
IOException
- if an I/O error occurs when writing the zip file, or
if two files or directories in the include list have the same
(simple) name, or an element in the include list doesn't
exist.public static boolean zipDir(File zipFile, File rootDir, int compressionLevel) throws IOException
rootDir
into a zip file. The zip file contains the root
directory as the only entry in its root.
zipFile
- the zip file that should be created. If it exists it will
be overwritten.rootDir
- the directory to pack.compressionLevel
- the desired compression level, see
ZipOutputStream.setLevel(int)
true
if all files and dirs are included,
false
if an error occurs reading a file or if a
directory is unreadable.
IOException
- if an I/O error occurspublic static boolean zipDir(File zipFile, File rootDir, int compressionLevel, FileUtil.ZipFileFilter filter, ExecutionMonitor exec) throws IOException, CanceledExecutionException
rootDir
into a zip file. The zip file contains the root
directory as the only entry in its root.
zipFile
- the zip file that should be created. If it exists it will
be overwritten.rootDir
- the directory to pack.compressionLevel
- the desired compression level, see
ZipOutputStream.setLevel(int)
filter
- each file (and dir) contained in the rootDir is only
included in the zip archive if it is accepted by the filter.
The rootDir is always included. Files from the
addRootFiles
list are also not filtered. Must not
be null.exec
- receives progress messages and is checked for cancel
requests. Optional, can be null.
true
if all files and dirs are included,
false
if an error occurs reading a file, if a
directory is unreadable, or a file in the
addRootFiles
list is a directory, not readable or
doesn't exist.
CanceledExecutionException
- if the operation was canceled through
the exec
IOException
- if an I/O error occurspublic static void unzip(File zipFile, File destDir) throws IOException
zipFile
- a ZIP filedestDir
- the destination directory, must already exist
IOException
- if an I/O error occurspublic static void unzip(ZipInputStream zipStream, File dir, int stripLevel) throws IOException
zipStream
- must contain a zip archive. Is unpacked an stored in the
specified directory.dir
- the destination directory the content of the zip stream is
stored instripLevel
- the number of path segments (directory levels) striped
off the file (and dir) names in the zip archive.
IOException
- if it was not able to store the contentpublic static File createTempDir(String prefix) throws IOException
prefix
- the prefix string to be used in generating the file's name
IOException
- if the directory could not be createdpublic static File createTempDir(String prefix, File dir) throws IOException
prefix
- the prefix string to be used in generating the file's namedir
- the directory in which the file is to be created, or
null
if the default temporary-file directory is
to be used
IOException
- if the directory could not be createdpublic static boolean chmod(File f, Boolean readable, Boolean writable, Boolean executable, boolean ownerOnly)
f
- a file or directory to change the permissions on (recursively).readable
- if the readable-bit should be set, or null
if its value shouldn't be changedwritable
- if the writable-bit should be set, or null
if its value shouldn't be changedexecutable
- if the executable-bit should be set, or
null
if its value shouldn't be changedownerOnly
- If true
, the read permission applies only
to the owner's read permission; otherwise, it applies to
everybody. If the underlying file system can not distinguish
the owner's read permission from that of others, then the
permission will apply to everybody, regardless of this value.
true
if and only if the operation succeeded. The
operation will fail if the user does not have permission to
change the access permissions of this abstract pathname.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |