Class NIOHelper
- Since:
- Intrexx 8.0.
- 
Method SummaryModifier and TypeMethodDescriptionstatic 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 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) 
- 
Method Details- 
getFileNameGet 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.- Parameters:
- p_path- The path.
- Returns:
- The file name as a string.
- Since:
- Intrexx 9.0.
 
- 
getNormalizedPathGet 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.- Parameters:
- p_file- The file.
- Returns:
- The normalized path.
- Since:
- Intrexx 9.0.
 
- 
getPathRelativeGet 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.- Parameters:
- p_dir- The base directory.
- p_file- The file for which the path relative to- p_dirshould be determined.
- Returns:
- The path of p_filerelative top_dir, ornullifp_diris not a parent ofp_file.
- Throws:
- IOException- - If an I/O error occurred.
- Since:
- Intrexx 9.0.
 
- 
isDirectoryEmptyCheck if the given directory is empty.- Parameters:
- p_dir- The directory.
- Returns:
- trueif the directory is empty, or- falseotherwise.
- Throws:
- NotDirectoryException- If the given path does not represent an existing directory.
- IOException- If an I/O error occurred.
- IllegalArgumentException- If the given path is- null.
- Since:
- Intrexx 9.0.
 
- 
containspublic 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.- Parameters:
- p_dir- The directory.
- p_filter- The filter,
- Returns:
- trueif the directory contains files or directories that are accepted by the given filter, or- falseotherwise.
- Throws:
- NotDirectoryException- If the given path does not represent an existing directory.
- IOException- If an I/O error occurred.
- IllegalArgumentException- If the given path is- null.
- Since:
- Intrexx 9.0.
 
- 
getFileSizeReturns the size of the file or directory tree.- Parameters:
- p_file- file or directory
- Returns:
- size of all files of the specified tree or of a single file
- Since:
- Intrexx 8.0.
 
- 
getMessageDigestHexCreate a lower-case hexadecimal encoded message digest from the given file.- Parameters:
- p_file- The file.
- p_md- The message digest to be used.
- Returns:
- The message digest.
- Throws:
- FileNotFoundException- If the file does not exist.
- IOException- If an I/O error occurred.
- Since:
- Intrexx 9.0.
 
- 
getMessageDigestCreate a message digest from the given file.- Parameters:
- p_file- The file.
- p_md- The message digest to be used.
- Returns:
- The message digest.
- Throws:
- FileNotFoundException- If the file does not exist.
- IOException- If an I/O error occurred.
- Since:
- Intrexx 9.0.
 
- 
getFileTextGet 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. - Parameters:
- p_file- The text file.
- Returns:
- The content of the given text file.
- Throws:
- 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.
- Since:
- Intrexx 9.0.
 
- 
getFileTextGet 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. - Parameters:
- p_file- The text file.
- p_encoding- The file encoding.
- Returns:
- The content of the given text file.
- Throws:
- 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.
- Since:
- Intrexx 9.0.
 
- 
listFilespublic 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.- Parameters:
- p_dir- The directory.
- p_filter- The filter,
- Returns:
- A list of files or directories that are accepted by the given
    filter (never null).
- Throws:
- NotDirectoryException- If the given path does not represent an existing directory.
- IOException- If an I/O error occurred.
- IllegalArgumentException- If the given path is- null.
- Since:
- Intrexx 9.0.
 
- 
copyDirCopy a directory recursively.p_destis the destination directory. If this directory does not exist, it will be created. The content of the source directory will be copied into it.- Parameters:
- p_dirDest- The destination directory.
- p_dirSrc- The directory to copy.
- Throws:
- IOException- If an I/O error occurred.
- Since:
- Intrexx 8.0.
 
- 
copyDirpublic static void copyDir(Path p_dirDest, Path p_dirSrc, boolean p_bCopyMarkedDirs) throws IOException Copy a directory recursively.p_destis the destination directory. If this directory does not exist, it will be created. The content of the source directory will be copied into it.- Parameters:
- p_dirDest- The destination directory.
- p_dirSrc- The directory to copy.
- p_bCopyMarkedDirs- copy directories, event if they are marked with a ".noexport" file. If this parameter is set to false, the destination directory is created but left empty.
- Throws:
- IOException- If an I/O error occurs.
- Since:
- Intrexx 8.0.
 
- 
copyDirpublic 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.
 p_destis the parent directory of the new directory.- Parameters:
- p_dirDest- The destination directory.
- p_dirSrc- The directory to copy.
- p_filter- File filter that filters the files that will be copied. If- nullis specified, no filter applies.
- Throws:
- IOException- If an I/O error occurred.
- Since:
- Intrexx 8.0.
 
- 
copyDirpublic 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.
 p_destis the parent directory of the new directory.- Parameters:
- p_dirDest- The destination directory.
- p_dirSrc- The directory to copy.
- p_filter- File filter that filters the files that will be copied. If- nullis specified, no filter applies.
- p_bCopyMarkedDirs- copy directories, event if they are marked with a ".noexport" file. If this parameter is set to false, the destination directory is created with a .noxexport file as the only content.
- Throws:
- IOException- If an I/O error occurred.
- Since:
- Intrexx 8.0.
 
- 
deleteDeletes 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.- Parameters:
- p_path- The directory path to delete.
- Throws:
- IOException- If an I/O error occurred.
- Since:
- Intrexx 8.0.
 
- 
isPathBelowCheck 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. - Parameters:
- p_dir- The containing directory (must exist physically).
- p_path- The path to test (is not required to exist physically).
- Returns:
- trueif the given file's location is below the given, directory, or- falseotherwise.
- Throws:
- NoSuchFileException- If the containing directory does not exist.
- IOException- If an I/O error occurred.
- IllegalArgumentException- If the given directory or path is- null.
- Since:
- Intrexx 9.0.
 
- 
getPathBelowGet a file object that represents a file or directory in a sub-path below the Java VM's working directory.- Parameters:
- p_strPath- The sub-path within the current working directory.
- Returns:
- A path object that represents a file or directory in a sub-path of the current working directory.
- Throws:
- IllegalArgumentException- If the given path is- nullor empty.
- SecurityException- If the given path references a file location outside the given directory.
- Since:
- Intrexx 9.0.
 
- 
getPathBelowGet a file object that represents a file or directory in a sub-path below a given directory.- Parameters:
- p_dir- The base directory where the given sub-path should be rooted.
- p_subs- The sub-path within the given directory.
- Returns:
- A file object that represents a file or directory in a sub-path of the given directory.
- Throws:
- IllegalArgumentException- If- p_diris- null, or if the directory- p_dirdoes not exist, or if- p_subsis- nullor empty or contains- nullor empty path elements.
- SecurityException- If- p_pathreferences a file location outside the given directory.
- Since:
- Intrexx 9.0.
 
- 
getUniqueNumberedFile- Returns:
- A file path base on the given file that does not exist.
- Since:
- Intrexx 9.0.
 
- 
stripFileNumber- Returns:
- The file with removed trailing file number.
- Since:
- Intrexx 9.0.
 
- 
newBufferedInputStreampublic 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.- Parameters:
- p_file- The path to the file to open.
- p_options- Options specifying how the file is opened.
- Returns:
- A new input stream.
- Throws:
- IllegalArgumentException- See- Files.newInputStream(Path, OpenOption...).
- UnsupportedOperationException- See- Files.newInputStream(Path, OpenOption...).
- SecurityException- See- Files.newInputStream(Path, OpenOption...).
- IOException- See- Files.newInputStream(Path, OpenOption...).
- Since:
- Intrexx 9.0.
 
- 
newBufferedOutputStreampublic 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. - Parameters:
- p_file- The path to the file to open.
- p_options- Options specifying how the file is opened.
- Returns:
- A new output stream.
- Throws:
- IllegalArgumentException- See- Files.newOutputStream(Path, OpenOption...).
- UnsupportedOperationException- See- Files.newOutputStream(Path, OpenOption...).
- SecurityException- See- Files.newOutputStream(Path, OpenOption...).
- IOException- See- Files.newOutputStream(Path, OpenOption...).
- Since:
- Intrexx 9.0.
 
- 
newBufferedObjectInputStreampublic 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. - Parameters:
- p_file- The path to the file to open.
- p_options- Options specifying how the file is opened.
- Returns:
- A new object input stream.
- Throws:
- IllegalArgumentException- See- Files.newInputStream(Path, OpenOption...).
- UnsupportedOperationException- See- Files.newInputStream(Path, OpenOption...).
- SecurityException- See- Files.newInputStream(Path, OpenOption...).
- IOException- See- Files.newInputStream(Path, OpenOption...).
- Since:
- Intrexx 9.0.
 
- 
newBufferedObjectOutputStreampublic 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. - Parameters:
- p_file- The path to the file to open.
- p_options- Options specifying how the file is opened.
- Returns:
- A new object output stream.
- Throws:
- IllegalArgumentException- See- Files.newOutputStream(Path, OpenOption...).
- UnsupportedOperationException- See- Files.newOutputStream(Path, OpenOption...).
- SecurityException- See- Files.newOutputStream(Path, OpenOption...).
- IOException- See- Files.newOutputStream(Path, OpenOption...).
- Since:
- Intrexx 9.0.
 
- 
createBackupFileCreate 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.- Parameters:
- p_file- The file to backup.
- Returns:
- The created backup file.
- Throws:
- IOException- If an I/O error occurred.
- Since:
- Intrexx 9.0.
 
 
-