Class CoreFileUtils

  • Direct Known Subclasses:
    FileUtils

    public class CoreFileUtils
    extends java.lang.Object
    This class provides the ability to create temporary files or directories in the Multi-Platform temporary directory, which is created when a wizard is started. Any temporary files or directories created through these methods are automatically cleaned up by the deleteTempFiles method, which is called when the wizard is exited.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String systemLF  
    • Constructor Summary

      Constructors 
      Constructor Description
      CoreFileUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addTempFile​(java.lang.String fileName)
      Adds an individual temp file name to the list of temporary files to be deleted by a call to deleteTempFiles.
      static java.lang.String appendSeparator​(java.lang.String path)
      Appends the File.separator to the end of the path if doesn't already contain one.
      static java.lang.String appendSeparator​(java.lang.String path, java.lang.String separator)
      Appends the separator specified to the end of the path if doesn't already contain one.
      static java.lang.String canonizePath​(java.lang.String path)  
      static void clearTempFile​(java.lang.String fileName)
      Clears an individual temp file name from the list of temporary files to be deleted by a call to deleteTempFiles.
      static void clearTempFiles()
      Clears the list of files that would have been deleted by a call to deleteTempFiles.
      static void close​(java.io.InputStream in)  
      static void close​(java.io.OutputStream out)  
      static boolean comparePaths​(java.lang.String path1, java.lang.String path2)
      Verifies whether two paths are the same taking multiple path separators and folder relocators within the path (i.e., "\." and "\..") into account.
      static int copy​(int bufferSize, java.io.InputStream in, java.io.OutputStream out)
      Copies the contents of the input stream to the output stream.
      static int copy​(int bufferSize, java.io.InputStream in, java.io.OutputStream out, int length)  
      static long copy​(int bufferSize, java.io.InputStream in, java.io.OutputStream out, long length)
      Copies the contents of the input stream to the output stream.
      static int copy​(java.io.InputStream in, java.io.OutputStream out)
      Copies the contents of the input stream to the output stream.
      static java.lang.String[] createDirs​(java.io.File target)
      Creates the directories required to make the path in target a legitimate path.
      static java.lang.String createFileName​(java.lang.String context, java.lang.String fileName)
      Returns a file name using context and fileName.
      static java.lang.String createTempDir()
      Creates an empty directory as a subdirectory of the Multi-Platform temporary directory.
      static java.lang.String createTempDirName()
      Creates a temporary directory name using a random number generator.
      static java.lang.String createTempFile()
      Creates an empty file (size of 0) in the Mullti-Platform temporary directory.
      static java.lang.String createTempFile​(java.net.URL source)
      Creates a temporary file from the specified source.
      static java.lang.String createTempFile​(java.net.URL source, java.lang.String fileName)
      Creates a temporary file from the specified source, and creates a temporary file with the specified fileName, copying the contents of the source file into the new file.
      static java.lang.String createTempFileName()
      Creates a temporary file name using a random number generator.
      static boolean deleteTempFile​(java.lang.String fileName)
      Deletes the specified file from the target machine, and removes it from the list of temp files to be deleted by a call to deleteTempFiles.
      protected static java.lang.String getIsjeTempDir()  
      static java.lang.String getParent​(java.lang.String fileName)  
      static java.lang.String getTempDir()
      Returns the temporary directory within which this class creates all of its temporary files and directories.
      protected static java.util.Vector getTempFiles()  
      static boolean isAbsolute​(java.lang.String fileName)  
      static boolean isFileSystemCaseSensitive()  
      static void main​(java.lang.String[] args)  
      static java.lang.String normalizeFileName​(java.lang.String fileName)  
      static java.lang.String normalizeFileName​(java.lang.String fileName, char normalSeparator)  
      protected static void resetCurrentTempDir()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • systemLF

        public static final java.lang.String systemLF
    • Constructor Detail

      • CoreFileUtils

        public CoreFileUtils()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
      • createTempDir

        public static java.lang.String createTempDir()
                                              throws java.io.IOException
        Creates an empty directory as a subdirectory of the Multi-Platform temporary directory. The directory is deleted when the deleteTempFiles method is called.
        Throws:
        java.io.IOException
      • createTempDirName

        public static java.lang.String createTempDirName()
        Creates a temporary directory name using a random number generator. The directory is not physically created, and no path information is included.
      • createTempFile

        public static java.lang.String createTempFile()
                                               throws java.io.IOException
        Creates an empty file (size of 0) in the Mullti-Platform temporary directory. The file is deleted when the deleteTempFiles method is called.
        Throws:
        java.io.IOException
      • createTempFile

        public static java.lang.String createTempFile​(java.net.URL source)
                                               throws java.io.IOException
        Creates a temporary file from the specified source. The filename is randomly generated and resides in the Multi-Platform temporary subdirectory. If you need to guarantee the name of the created file, use the createTempFile(java.net.URL, String) method.

        Files created by this method are deleted by a call to the deleteTempFiles method.

        Throws:
        java.io.IOException
      • createTempFile

        public static java.lang.String createTempFile​(java.net.URL source,
                                                      java.lang.String fileName)
                                               throws java.io.IOException
        Creates a temporary file from the specified source, and creates a temporary file with the specified fileName, copying the contents of the source file into the new file. Files created by this method are deleted by a call to deleteTempFiles. It first attempts to create the specified fileName directly in the Multi-Platform temporary directory. If it cannot, it creates a new subdirectory of the Multi-Platform temporary directory, and creates the file there.
        Throws:
        java.io.IOException
      • deleteTempFile

        public static boolean deleteTempFile​(java.lang.String fileName)
        Deletes the specified file from the target machine, and removes it from the list of temp files to be deleted by a call to deleteTempFiles. If the file cannot be deleted from the target machine, it is left in the temp files list.
      • clearTempFiles

        public static void clearTempFiles()
        Clears the list of files that would have been deleted by a call to deleteTempFiles.
      • addTempFile

        public static void addTempFile​(java.lang.String fileName)
        Adds an individual temp file name to the list of temporary files to be deleted by a call to deleteTempFiles.
      • clearTempFile

        public static void clearTempFile​(java.lang.String fileName)
        Clears an individual temp file name from the list of temporary files to be deleted by a call to deleteTempFiles.
      • getTempFiles

        protected static java.util.Vector getTempFiles()
      • getTempDir

        public static java.lang.String getTempDir()
        Returns the temporary directory within which this class creates all of its temporary files and directories.
      • getIsjeTempDir

        protected static java.lang.String getIsjeTempDir()
      • resetCurrentTempDir

        protected static void resetCurrentTempDir()
      • createTempFileName

        public static java.lang.String createTempFileName()
        Creates a temporary file name using a random number generator. The generated file has a "tmp" extension. The file is not physically created, and no path information is included.
      • createDirs

        public static java.lang.String[] createDirs​(java.io.File target)
                                             throws java.io.IOException
        Creates the directories required to make the path in target a legitimate path. For example, if "/foo/bar/now" is created, and only "/foo" exists prior to this method being called, then it creates the remaining subdirectories "/foo/bar" and "/foo/bar/now". It returns an array that contains "/foo/bar" and /"/foo/bar/now".
        Throws:
        java.io.IOException
      • createFileName

        public static java.lang.String createFileName​(java.lang.String context,
                                                      java.lang.String fileName)
        Returns a file name using context and fileName. If fileName is absolute, it is returned without modification. If fileName is relative, it is appended to context to form a qualified file name. fileName can be null, in which case context is returned. If context is null, it is treated as if it is an empty string.
      • getParent

        public static java.lang.String getParent​(java.lang.String fileName)
      • isAbsolute

        public static boolean isAbsolute​(java.lang.String fileName)
      • normalizeFileName

        public static java.lang.String normalizeFileName​(java.lang.String fileName,
                                                         char normalSeparator)
      • normalizeFileName

        public static java.lang.String normalizeFileName​(java.lang.String fileName)
      • appendSeparator

        public static java.lang.String appendSeparator​(java.lang.String path)
        Appends the File.separator to the end of the path if doesn't already contain one.
        Parameters:
        path - to append the separator.
        Returns:
        String resulting in a new string.
      • appendSeparator

        public static java.lang.String appendSeparator​(java.lang.String path,
                                                       java.lang.String separator)
        Appends the separator specified to the end of the path if doesn't already contain one.
        Parameters:
        path - Path to append the separator.
        separator - Separator string to be appended.
        Returns:
        - String resulting in a new string.
      • canonizePath

        public static java.lang.String canonizePath​(java.lang.String path)
      • comparePaths

        public static boolean comparePaths​(java.lang.String path1,
                                           java.lang.String path2)
        Verifies whether two paths are the same taking multiple path separators and folder relocators within the path (i.e., "\." and "\..") into account.
      • copy

        public static int copy​(java.io.InputStream in,
                               java.io.OutputStream out)
                        throws java.io.IOException
        Copies the contents of the input stream to the output stream. Neither stream is closed by this method.
        Throws:
        java.io.IOException
      • copy

        public static int copy​(int bufferSize,
                               java.io.InputStream in,
                               java.io.OutputStream out,
                               int length)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • copy

        public static long copy​(int bufferSize,
                                java.io.InputStream in,
                                java.io.OutputStream out,
                                long length)
                         throws java.io.IOException
        Copies the contents of the input stream to the output stream. It uses a buffer of the specified size to perform the copy. It copies the number of bytes specified by the length argument. To copy the entire stream, use a length of Integer.MAX_VALUE. Neither stream is closed by this method.
        Throws:
        java.io.IOException
      • copy

        public static int copy​(int bufferSize,
                               java.io.InputStream in,
                               java.io.OutputStream out)
                        throws java.io.IOException
        Copies the contents of the input stream to the output stream. It uses a buffer of the specified size to perform the copy. Neither stream is closed by this method.
        Throws:
        java.io.IOException
      • close

        public static void close​(java.io.InputStream in)
      • close

        public static void close​(java.io.OutputStream out)
      • isFileSystemCaseSensitive

        public static boolean isFileSystemCaseSensitive()