Class FileUtils

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

public class FileUtils extends Object
A set of utilities for working with Files
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • fileIsFile

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

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

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

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

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

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

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

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

      public static long fileLastModified(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(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(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(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.
    • fileMkDir

      public static boolean fileMkDir(File target)
      Calls File.mkdir() 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(File file)
      Delete file
      Returns:
      true if file was deleted
    • ensureDirExists

      public static boolean ensureDirExists(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(Closeable closeable)
      Close the closeable object
      Parameters:
      closeable -
    • setUserReadWriteOnly

      public static boolean setUserReadWriteOnly(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 Boolean fileCreate(File target) throws 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:
      IOException