Klasse NIOHelper
- Seit:
- Intrexx 8.0.
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic booleancontains(Path p_dir, DirectoryStream.Filter<Path> p_filter) Check if the given directory contains files or directories that are accepted by the given filter.static voidCopy a directory recursively.static voidCopy a directory recursively.static voidcopyDir(Path p_dirDest, Path p_dirSrc, DirectoryStream.Filter<Path> p_filter) Copy a directory recursively.static voidcopyDir(Path p_dirDest, Path p_dirSrc, DirectoryStream.Filter<Path> p_filter, boolean p_bCopyMarkedDirs) Copy a directory recursively.static voidcopyDir(Path p_dirDest, Path p_dirSrc, DirectoryStream.Filter<Path> p_filter, boolean p_bCopyMarkedDirs, de.uplanet.util.Progress p_progress) Copy a directory recursively.static PathcreateBackupFile(Path p_file, Path p_dir) Create a backup of the given file.static voidDeletes a directory tree recursively.static StringgetFileName(Path p_path) Get the name of the farthest element from the root of the given path as a string.static longgetFileSize(Path p_file) Returns the size of the file or directory tree.static StringgetFileText(Path p_file) Get the content of a small UTF-8 encoded text file.static StringgetFileText(Path p_file, Charset p_encoding) Get the content of a small text file.static byte[]getMessageDigest(Path p_file, MessageDigest p_md) Create a message digest from the given file.static StringgetMessageDigestHex(Path p_file, MessageDigest p_md) Create a lower-case hexadecimal encoded message digest from the given file.static StringgetNormalizedPath(Path p_file) Get the normalized path of an existing file or directory.static PathgetPathBelow(String p_strPath) Get a file object that represents a file or directory in a sub-path below the Java VM's working directory.static PathgetPathBelow(Path p_dir, String... p_subs) Get a file object that represents a file or directory in a sub-path below a given directory.static StringgetPathRelative(Path p_dir, Path p_file) Get the path of an existing file or directory below the given existing directory relative to this directory.static PathgetUniqueNumberedFile(Path p_file) static booleanisDirectoryEmpty(Path p_dir) Check if the given directory is empty.static booleanisPathBelow(Path p_dir, Path p_path) Check if the given file's or directory's location is below the given existing directory.listFiles(Path p_dir, DirectoryStream.Filter<Path> p_filter) Get a list of files or directories that are accepted by the given filter.static InputStreamnewBufferedInputStream(Path p_file, OpenOption... p_options) Get an input stream that provides better read performance than the input stream returned byFiles.newInputStream(Path, OpenOption...)in cases where many small read operations occur.static ObjectInputStreamnewBufferedObjectInputStream(Path p_file, OpenOption... p_options) Get a buffered object input stream.static ObjectOutputStreamnewBufferedObjectOutputStream(Path p_file, OpenOption... p_options) Get a buffered object output stream.static OutputStreamnewBufferedOutputStream(Path p_file, OpenOption... p_options) Get an output stream that provides better write performance than the output stream returned byFiles.newOutputStream(Path, OpenOption...)in cases where many small write operations occur.static PathstripFileNumber(Path p_file)
-
Methodendetails
-
getFileName
Get the name of the farthest element from the root of the given path as a string. The call is equivalent top_path.getFileName().toString()
This method is intended to be referenced in places where otherwise clumsy lambda expressions were needed.- Parameter:
p_path- The path.- Gibt zurück:
- The file name as a string.
- Seit:
- Intrexx 9.0.
-
getNormalizedPath
Get the normalized path of an existing file or directory.The returned path's file separators are replaced with forward slashes ('/') if the operating system's file separator is not the forward slash.
Note: This method is not equivalent to
IOHelper.getNormalizedPath(File)since it does not necessarily return an absolute path and does not append a trailing slash to paths that refer to a directory.- Parameter:
p_file- The file.- Gibt zurück:
- The normalized path.
- Seit:
- Intrexx 9.0.
-
getPathRelative
Get the path of an existing file or directory below the given existing directory relative to this directory.The returned path's file separators are normalized to forward slash ('/') if the operating system's file separator is not the forward slash.
If
p_filedenotes a directory the returned path, if notnull, has a trailing forward slash.- Parameter:
p_dir- The base directory.p_file- The file for which the path relative top_dirshould be determined.- Gibt zurück:
- The path of
p_filerelative top_dir, ornullifp_diris not a parent ofp_file. - Löst aus:
IOException- - If an I/O error occurred.- Seit:
- Intrexx 9.0.
-
isDirectoryEmpty
Check if the given directory is empty.- Parameter:
p_dir- The directory.- Gibt zurück:
trueif the directory is empty, orfalseotherwise.- Löst aus:
NotDirectoryException- If the given path does not represent an existing directory.IOException- If an I/O error occurred.IllegalArgumentException- If the given path isnull.- Seit:
- Intrexx 9.0.
-
contains
public static boolean contains(Path p_dir, DirectoryStream.Filter<Path> p_filter) throws NotDirectoryException, IOException Check if the given directory contains files or directories that are accepted by the given filter.- Parameter:
p_dir- The directory.p_filter- The filter,- Gibt zurück:
trueif the directory contains files or directories that are accepted by the given filter, orfalseotherwise.- Löst aus:
NotDirectoryException- If the given path does not represent an existing directory.IOException- If an I/O error occurred.IllegalArgumentException- If the given path isnull.- Seit:
- Intrexx 9.0.
-
getFileSize
Returns the size of the file or directory tree.- Parameter:
p_file- file or directory- Gibt zurück:
- size of all files of the specified tree or of a single file
- Seit:
- Intrexx 8.0.
-
getMessageDigestHex
Create a lower-case hexadecimal encoded message digest from the given file.- Parameter:
p_file- The file.p_md- The message digest to be used.- Gibt zurück:
- The message digest.
- Löst aus:
FileNotFoundException- If the file does not exist.IOException- If an I/O error occurred.- Seit:
- Intrexx 9.0.
-
getMessageDigest
Create a message digest from the given file.- Parameter:
p_file- The file.p_md- The message digest to be used.- Gibt zurück:
- The message digest.
- Löst aus:
FileNotFoundException- If the file does not exist.IOException- If an I/O error occurred.- Seit:
- Intrexx 9.0.
-
getFileText
Get the content of a small UTF-8 encoded text file.Note that this method is intended for simple cases where it is convenient to read all bytes into a byte array. It is not intended for reading in large files.
- Parameter:
p_file- The text file.- Gibt zurück:
- The content of the given text file.
- Löst aus:
FileNotFoundException- If the file does not exist.IOException- If an I/O error occurred.OutOfMemoryError- If the file is too large to be read into memory.- Seit:
- Intrexx 9.0.
-
getFileText
Get the content of a small text file.Note that this method is intended for simple cases where it is convenient to read all bytes into a byte array. It is not intended for reading in large files.
- Parameter:
p_file- The text file.p_encoding- The file encoding.- Gibt zurück:
- The content of the given text file.
- Löst aus:
FileNotFoundException- If the file does not exist.IOException- If an I/O error occurred.OutOfMemoryError- If the file is too large to be read into memory.- Seit:
- Intrexx 9.0.
-
listFiles
public static ArrayList<Path> listFiles(Path p_dir, DirectoryStream.Filter<Path> p_filter) throws NotDirectoryException, IOException Get a list of files or directories that are accepted by the given filter.Note: This method may consume large amounts of memory. Avoid using it whenever possible and use a
DirectoryStreaminstead.- Parameter:
p_dir- The directory.p_filter- The filter,- Gibt zurück:
- A list of files or directories that are accepted by the given
filter (never
null). - Löst aus:
NotDirectoryException- If the given path does not represent an existing directory.IOException- If an I/O error occurred.IllegalArgumentException- If the given path isnull.- Seit:
- Intrexx 9.0.
-
copyDir
Copy a directory recursively.The destination directory will be created if it does not exist. The content of the source directory will be copied into it. Files existing in the target tree will be replaced.
- Parameter:
p_dirDest- The destination directory.p_dirSrc- The directory to copy.- Löst aus:
IOException- If an I/O error occurred.- Seit:
- Intrexx 8.0.
-
copyDir
public static void copyDir(Path p_dirDest, Path p_dirSrc, DirectoryStream.Filter<Path> p_filter) throws IOException Copy a directory recursively.Copy only the files matching the specified file filter.
The destination directory will be created if it does not exist. The content of the source directory will be copied into it. Files existing in the target tree will be replaced.
- Parameter:
p_dirDest- The destination directory.p_dirSrc- The directory to copy.p_filter- File filter that filters the files that will be copied. Ifnullis specified, no filter applies.- Löst aus:
IOException- If an I/O error occurred.- Seit:
- Intrexx 8.0.
-
copyDir
public static void copyDir(Path p_dirDest, Path p_dirSrc, boolean p_bCopyMarkedDirs) throws IOException Copy a directory recursively.The destination directory will be created if it does not exist. The content of the source directory will be copied into it. Files existing in the target tree will be replaced.
- Parameter:
p_dirDest- The destination directory.p_dirSrc- The directory to copy.p_bCopyMarkedDirs- copy directories, event if they are marked with a.noxexportfile. If this parameter is set tofalse, the destination directory is created but left empty.- Löst aus:
IOException- If an I/O error occurs.- Seit:
- Intrexx 8.0.
-
copyDir
public static void copyDir(Path p_dirDest, Path p_dirSrc, DirectoryStream.Filter<Path> p_filter, boolean p_bCopyMarkedDirs) throws IOException Copy a directory recursively.Copy only the files matching the specified file filter.
The destination directory will be created if it does not exist. The content of the source directory will be copied into it. Files existing in the target tree will be replaced.
- Parameter:
p_dirDest- The destination directory.p_dirSrc- The directory to copy.p_filter- File filter that filters the files that will be copied. Ifnullis specified, no filter applies.p_bCopyMarkedDirs- copy directories, event if they are marked with a.noxexportfile. If this parameter is set tofalse, the destination directory is created with a.noxexportfile as the only content.- Löst aus:
IOException- If an I/O error occurred.- Seit:
- Intrexx 8.0.
-
copyDir
public static void copyDir(Path p_dirDest, Path p_dirSrc, DirectoryStream.Filter<Path> p_filter, boolean p_bCopyMarkedDirs, de.uplanet.util.Progress p_progress) throws IOException Copy a directory recursively.Copy only the files matching the specified file filter.
The destination directory will be created if it does not exist. The content of the source directory will be copied into it. Files existing in the target tree will be replaced.
- Parameter:
p_dirDest- The destination directory.p_dirSrc- The directory to copy.p_filter- File filter that filters the files that will be copied. Ifnullis specified, no filter applies.p_bCopyMarkedDirs- copy directories, event if they are marked with a.noxexportfile. If this parameter is set tofalse, the destination directory is created with a.noxexportfile as the only content.p_progress- The progress (could benull).- Löst aus:
IOException- If an I/O error occurred.- Seit:
- Intrexx 12.0.
-
delete
Deletes a directory tree recursively. If the specified path refers to a file, this method deletes it. If it is a directory, all items of the tree are deleted as well as the specified directory itself.- Parameter:
p_path- The directory path to delete.- Löst aus:
IOException- If an I/O error occurred.- Seit:
- Intrexx 8.0.
-
isPathBelow
Check if the given file's or directory's location is below the given existing directory. The file or directory given as the second parameter is not required to exist.If the given path is relative it is assumed to be relative to the current working directory.
- Parameter:
p_dir- The containing directory (must exist physically).p_path- The path to test (is not required to exist physically).- Gibt zurück:
trueif the given file's location is below the given, directory, orfalseotherwise.- Löst aus:
NoSuchFileException- If the containing directory does not exist.IOException- If an I/O error occurred.IllegalArgumentException- If the given directory or path isnull.- Seit:
- Intrexx 9.0.
-
getPathBelow
Get a file object that represents a file or directory in a sub-path below the Java VM's working directory.- Parameter:
p_strPath- The sub-path within the current working directory.- Gibt zurück:
- A path object that represents a file or directory in a sub-path of the current working directory.
- Löst aus:
IllegalArgumentException- If the given path isnullor empty.SecurityException- If the given path references a file location outside the given directory.- Seit:
- Intrexx 9.0.
-
getPathBelow
Get a file object that represents a file or directory in a sub-path below a given directory.- Parameter:
p_dir- The base directory where the given sub-path should be rooted.p_subs- The sub-path within the given directory.- Gibt zurück:
- A file object that represents a file or directory in a sub-path of the given directory.
- Löst aus:
IllegalArgumentException- Ifp_dirisnull, or if the directoryp_dirdoes not exist, or ifp_subsisnullor empty or containsnullor empty path elements.SecurityException- Ifp_pathreferences a file location outside the given directory.- Seit:
- Intrexx 9.0.
-
getUniqueNumberedFile
- Gibt zurück:
- A file path base on the given file that does not exist.
- Seit:
- Intrexx 9.0.
-
stripFileNumber
- Gibt zurück:
- The file with removed trailing file number.
- Seit:
- Intrexx 9.0.
-
newBufferedInputStream
public static InputStream newBufferedInputStream(Path p_file, OpenOption... p_options) throws IOException Get an input stream that provides better read performance than the input stream returned byFiles.newInputStream(Path, OpenOption...)in cases where many small read operations occur.Note: The returned input stream is not guaranteed to be thread-safe.
Note: If you need an input stream that supports the
markandresetoperations you must not use this method.- Parameter:
p_file- The path to the file to open.p_options- Options specifying how the file is opened.- Gibt zurück:
- A new input stream.
- Löst aus:
IllegalArgumentException- SeeFiles.newInputStream(Path, OpenOption...).UnsupportedOperationException- SeeFiles.newInputStream(Path, OpenOption...).SecurityException- SeeFiles.newInputStream(Path, OpenOption...).IOException- SeeFiles.newInputStream(Path, OpenOption...).- Seit:
- Intrexx 9.0.
-
newBufferedOutputStream
public static OutputStream newBufferedOutputStream(Path p_file, OpenOption... p_options) throws IOException Get an output stream that provides better write performance than the output stream returned byFiles.newOutputStream(Path, OpenOption...)in cases where many small write operations occur.Note: The returned output stream is not guaranteed to be thread-safe.
- Parameter:
p_file- The path to the file to open.p_options- Options specifying how the file is opened.- Gibt zurück:
- A new output stream.
- Löst aus:
IllegalArgumentException- SeeFiles.newOutputStream(Path, OpenOption...).UnsupportedOperationException- SeeFiles.newOutputStream(Path, OpenOption...).SecurityException- SeeFiles.newOutputStream(Path, OpenOption...).IOException- SeeFiles.newOutputStream(Path, OpenOption...).- Seit:
- Intrexx 9.0.
-
newBufferedObjectInputStream
public static ObjectInputStream newBufferedObjectInputStream(Path p_file, OpenOption... p_options) throws IOException Get a buffered object input stream.Note: The returned input stream is not guaranteed to be thread-safe.
- Parameter:
p_file- The path to the file to open.p_options- Options specifying how the file is opened.- Gibt zurück:
- A new object input stream.
- Löst aus:
IllegalArgumentException- SeeFiles.newInputStream(Path, OpenOption...).UnsupportedOperationException- SeeFiles.newInputStream(Path, OpenOption...).SecurityException- SeeFiles.newInputStream(Path, OpenOption...).IOException- SeeFiles.newInputStream(Path, OpenOption...).- Seit:
- Intrexx 9.0.
-
newBufferedObjectOutputStream
public static ObjectOutputStream newBufferedObjectOutputStream(Path p_file, OpenOption... p_options) throws IOException Get a buffered object output stream.Note: The returned output stream is not guaranteed to be thread-safe.
- Parameter:
p_file- The path to the file to open.p_options- Options specifying how the file is opened.- Gibt zurück:
- A new object output stream.
- Löst aus:
IllegalArgumentException- SeeFiles.newOutputStream(Path, OpenOption...).UnsupportedOperationException- SeeFiles.newOutputStream(Path, OpenOption...).SecurityException- SeeFiles.newOutputStream(Path, OpenOption...).IOException- SeeFiles.newOutputStream(Path, OpenOption...).- Seit:
- Intrexx 9.0.
-
createBackupFile
Create a backup of the given file.The backuo file has the same name as the original file with the suffix
.yyyy-MM-dd-HH-mm-ss.bakcontaining a timestamp in the default time zone appended.- Parameter:
p_file- The file to backup.- Gibt zurück:
- The created backup file.
- Löst aus:
IOException- If an I/O error occurred.- Seit:
- Intrexx 9.0.
-