com.ibm.wsspi.kernel.service.utils

Class FileUtils

  • java.lang.Object
    • com.ibm.wsspi.kernel.service.utils.FileUtils


  • public class FileUtils
    extends java.lang.Object
    A set of utilities for working with Files
    • Constructor Summary

      Constructors 
      Constructor and Description
      FileUtils() 
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      static boolean ensureDirExists(java.io.File dir)
      Calls File.mkdirs() and File.exists() on the specified target
      static boolean fileCanRead(java.io.File target)
      Execute the File.canRead() from within a PrivilegedAction.
      static boolean fileCanWrite(java.io.File target)
      Execute the File.canWrite() from within a PrivilegedAction.
      static java.lang.Boolean fileCreate(java.io.File target)
      Calls File.createNewFile() on the specified target
      static boolean fileDelete(java.io.File file)
      Delete file
      static boolean fileExists(java.io.File target)
      Execute the File.exists() from within a PrivilegedAction.
      static boolean fileIsDirectory(java.io.File target)
      Execute the File.isDirectory() from within a PrivilegedAction.
      static boolean fileIsFile(java.io.File target)
      Execute the File.isFile() from within a PrivilegedAction.
      static long fileLastModified(java.io.File target)
      Execute the File.lastModified() from within a PrivilegedAction.
      static long fileLength(java.io.File target)
      Execute the File.length() from within a PrivilegedAction.
      static boolean fileMkDirs(java.io.File target)
      Calls File.mkdirs() on the specified target from within a PrivilegedAction.
      static java.io.FileOutputStream getFileOutputStream(java.io.File target)
      Create a new FileOutputStream for the file within a PrivilegedAction.
      static java.io.InputStream getInputStream(java.io.File target)
      Create a new InputStream for the file within a PrivilegedAction.
      static java.lang.String[] list(java.io.File target)
      Execute the File.list() from within a PrivilegedAction.
      static java.io.File[] listFiles(java.io.File target)
      Execute the File.listFiles() from within a PrivilegedAction.
      static boolean setUserReadWriteOnly(java.io.File file)
      Set the file permissions of the file to be user rw only.
      static boolean tryToClose(java.io.Closeable closeable)
      Close the closeable object
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileUtils

        public FileUtils()
    • Method Detail

      • fileIsFile

        public static boolean fileIsFile(java.io.File target)
        Execute the File.isFile() from within a PrivilegedAction.
        Parameters:
        f -
        Returns:
      • fileIsDirectory

        public static boolean fileIsDirectory(java.io.File target)
        Execute the File.isDirectory() from within a PrivilegedAction.
        Parameters:
        f -
        Returns:
      • fileExists

        public static boolean fileExists(java.io.File target)
        Execute the File.exists() from within a PrivilegedAction.
        Parameters:
        target -
        Returns:
      • fileLength

        public static long fileLength(java.io.File target)
        Execute the File.length() from within a PrivilegedAction.
        Parameters:
        target -
        Returns:
      • listFiles

        public static java.io.File[] listFiles(java.io.File target)
        Execute the File.listFiles() from within a PrivilegedAction.
        Parameters:
        f -
        Returns:
      • list

        public static java.lang.String[] list(java.io.File target)
        Execute the File.list() from within a PrivilegedAction.
        Parameters:
        f -
        Returns:
      • getInputStream

        public static java.io.InputStream getInputStream(java.io.File target)
                                                  throws java.io.FileNotFoundException
        Create a new InputStream for the file within a PrivilegedAction.
        Throws:
        java.io.FileNotFoundException
      • getFileOutputStream

        public static java.io.FileOutputStream getFileOutputStream(java.io.File target)
                                                            throws java.io.FileNotFoundException
        Create a new FileOutputStream for the file within a PrivilegedAction.
        Throws:
        java.io.FileNotFoundException
      • fileLastModified

        public static long fileLastModified(java.io.File target)
        Execute the File.lastModified() from within a PrivilegedAction.
        Parameters:
        target - The file to get the last modified for
        Returns:
        The last modified for the file
      • fileCanRead

        public static boolean fileCanRead(java.io.File target)
        Execute the File.canRead() from within a PrivilegedAction.
        Parameters:
        target - The file to test if it can be read
        Returns:
        true if the file can be read
      • fileCanWrite

        public static boolean fileCanWrite(java.io.File target)
        Execute the File.canWrite() from within a PrivilegedAction.
        Parameters:
        target - The file to test if it can be written
        Returns:
        true if the file can be written
      • fileMkDirs

        public static boolean fileMkDirs(java.io.File target)
        Calls File.mkdirs() on the specified target from within a PrivilegedAction.
        Parameters:
        target - The tarket to make a directory for
        Returns:
        true if this succeeded.
      • fileDelete

        public static boolean fileDelete(java.io.File file)
        Delete file
        Returns:
        true if file was deleted
      • ensureDirExists

        public static boolean ensureDirExists(java.io.File dir)
        Calls File.mkdirs() and File.exists() on the specified target
        Parameters:
        target - The target to check for existence or to create if it doesn't exist
        Returns:
        true if either call succeeded.
      • tryToClose

        public static boolean tryToClose(java.io.Closeable closeable)
        Close the closeable object
        Parameters:
        closeable -
      • setUserReadWriteOnly

        public static boolean setUserReadWriteOnly(java.io.File file)
        Set the file permissions of the file to be user rw only.

        This is a best effort attempt as Windows does NOT play nicely with file perms.

        Parameters:
        an - existing File
      • fileCreate

        public static java.lang.Boolean fileCreate(java.io.File target)
                                            throws java.io.IOException
        Calls File.createNewFile() on the specified target
        Parameters:
        target - The target to create if it doesn't exist
        Returns:
        true if call succeeded.
        Throws:
        java.io.IOException