Package de.uplanet.io

Klasse NIOHelper

java.lang.Object
de.uplanet.io.NIOHelper

@Scriptable public final class NIOHelper extends Object
NIOHelper class utility.
Seit:
Intrexx 8.0.
  • Methodendetails

    • getFileName

      public static String getFileName(Path p_path)
      Get the name of the farthest element from the root of the given path as a string. The call is equivalent to
       p_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

      public static String getNormalizedPath(Path p_file)
      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

      public static String getPathRelative(Path p_dir, Path p_file) throws IOException
      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_file denotes a directory the returned path, if not null, has a trailing forward slash.

      Parameter:
      p_dir - The base directory.
      p_file - The file for which the path relative to p_dir should be determined.
      Gibt zurück:
      The path of p_file relative to p_dir, or null if p_dir is not a parent of p_file.
      Löst aus:
      IOException - - If an I/O error occurred.
      Seit:
      Intrexx 9.0.
    • isDirectoryEmpty

      public static boolean isDirectoryEmpty(Path p_dir) throws NotDirectoryException, IOException
      Check if the given directory is empty.
      Parameter:
      p_dir - The directory.
      Gibt zurück:
      true if the directory is empty, or false otherwise.
      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 is null.
      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:
      true if the directory contains files or directories that are accepted by the given filter, or false otherwise.
      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 is null.
      Seit:
      Intrexx 9.0.
    • getFileSize

      public static long getFileSize(Path p_file)
      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

      public static String getMessageDigestHex(Path p_file, MessageDigest p_md) throws IOException
      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

      public static byte[] getMessageDigest(Path p_file, MessageDigest p_md) throws IOException
      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

      public static String getFileText(Path p_file) throws IOException
      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

      public static String getFileText(Path p_file, Charset p_encoding) throws IOException
      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 DirectoryStream instead.

      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 is null.
      Seit:
      Intrexx 9.0.
    • copyDir

      public static void copyDir(Path p_dirDest, Path p_dirSrc) 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.
      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. If null is 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 .noxexport file. If this parameter is set to false, 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. If null is specified, no filter applies.
      p_bCopyMarkedDirs - copy directories, event if they are marked with a .noxexport file. If this parameter is set to false, the destination directory is created with a .noxexport file 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. If null is specified, no filter applies.
      p_bCopyMarkedDirs - copy directories, event if they are marked with a .noxexport file. If this parameter is set to false, the destination directory is created with a .noxexport file as the only content.
      p_progress - The progress (could be null).
      Löst aus:
      IOException - If an I/O error occurred.
      Seit:
      Intrexx 12.0.
    • delete

      public static void delete(Path p_path) throws IOException
      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

      public static boolean isPathBelow(Path p_dir, Path p_path) throws NoSuchFileException, IOException
      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:
      true if the given file's location is below the given, directory, or false otherwise.
      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 is null.
      Seit:
      Intrexx 9.0.
    • getPathBelow

      public static Path getPathBelow(String p_strPath)
      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 is null or empty.
      SecurityException - If the given path references a file location outside the given directory.
      Seit:
      Intrexx 9.0.
    • getPathBelow

      public static Path getPathBelow(Path p_dir, String... p_subs)
      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 - If p_dir is null, or if the directory p_dir does not exist, or if p_subs is null or empty or contains null or empty path elements.
      SecurityException - If p_path references a file location outside the given directory.
      Seit:
      Intrexx 9.0.
    • getUniqueNumberedFile

      public static Path getUniqueNumberedFile(Path p_file)
      Gibt zurück:
      A file path base on the given file that does not exist.
      Seit:
      Intrexx 9.0.
    • stripFileNumber

      public static Path stripFileNumber(Path p_file)
      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 by Files.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 mark and reset operations 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 - See Files.newInputStream(Path, OpenOption...).
      UnsupportedOperationException - See Files.newInputStream(Path, OpenOption...).
      SecurityException - See Files.newInputStream(Path, OpenOption...).
      IOException - See Files.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 by Files.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 - See Files.newOutputStream(Path, OpenOption...).
      UnsupportedOperationException - See Files.newOutputStream(Path, OpenOption...).
      SecurityException - See Files.newOutputStream(Path, OpenOption...).
      IOException - See Files.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 - See Files.newInputStream(Path, OpenOption...).
      UnsupportedOperationException - See Files.newInputStream(Path, OpenOption...).
      SecurityException - See Files.newInputStream(Path, OpenOption...).
      IOException - See Files.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 - See Files.newOutputStream(Path, OpenOption...).
      UnsupportedOperationException - See Files.newOutputStream(Path, OpenOption...).
      SecurityException - See Files.newOutputStream(Path, OpenOption...).
      IOException - See Files.newOutputStream(Path, OpenOption...).
      Seit:
      Intrexx 9.0.
    • createBackupFile

      public static Path createBackupFile(Path p_file, Path p_dir) throws IOException
      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.bak containing 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.