Class FileObjectUtils

java.lang.Object
org.apache.commons.vfs2.util.FileObjectUtils

public final class FileObjectUtils extends Object
Utility methods for FileObject.
  • Constructor Details

    • FileObjectUtils

      private FileObjectUtils()
  • Method Details

    • exists

      public static boolean exists(FileObject fileObject) throws FileSystemException
      Null-safe call to FileObject.exists().
      Parameters:
      fileObject - the file object to test, may be null.
      Returns:
      false if fileObject is null, otherwise, see FileObject.exists().
      Throws:
      FileSystemException - On error determining if this file exists.
      Since:
      2.4
    • getAbstractFileObject

      public static AbstractFileObject getAbstractFileObject(FileObject fileObject) throws FileSystemException
      Gets access to the base object even if decorated.
      Parameters:
      fileObject - The FileObject.
      Returns:
      The decorated FileObject or null.
      Throws:
      FileSystemException - if an error occurs.
    • getContentAsByteArray

      public static byte[] getContentAsByteArray(FileObject file) throws IOException
      Gets the content of a file object, as a byte array.
      Parameters:
      file - Gets the contents of this file object.
      Returns:
      The content as a byte array.
      Throws:
      IOException - if the file content cannot be accessed.
      Since:
      2.6.0
    • getContentAsString

      public static String getContentAsString(FileObject file, Charset charset) throws IOException
      Gets the content of a file as a String.
      Parameters:
      file - Gets the contents of this file object.
      charset - The file character set, may be null.
      Returns:
      The content as a string.
      Throws:
      IOException - if the file content cannot be accessed.
      Since:
      2.4
    • getContentAsString

      public static String getContentAsString(FileObject file, String charset) throws IOException
      Returns the content of a file as a String.
      Parameters:
      file - Gets the contents of this file object.
      charset - The file character set, may be null.
      Returns:
      The content as a string.
      Throws:
      IOException - if the file content cannot be accessed.
      Since:
      2.4
    • isInstanceOf

      public static boolean isInstanceOf(FileObject fileObject, Class<?> wantedClass) throws FileSystemException
      Checks if the given FileObject is instance of given class argument.
      Parameters:
      fileObject - The FileObject.
      wantedClass - The Class to check.
      Returns:
      true if fileObject is an instance of the specified Class.
      Throws:
      FileSystemException - if an error occurs.
    • readProperties

      public static Properties readProperties(FileObject fileObject) throws FileSystemException, IOException
      Reads the given file into a new Properties.
      Parameters:
      fileObject - the file to read
      Returns:
      a new Properties.
      Throws:
      IOException - On error getting this file's content.
      FileSystemException - On error getting this file's content.
      IOException - On error getting this file's content.
      Since:
      2.4
    • readProperties

      public static Properties readProperties(FileObject fileObject, Properties properties) throws FileSystemException, IOException
      Reads the given file into a new given Properties.
      Parameters:
      fileObject - the file to read
      properties - the destination
      Returns:
      a new Properties.
      Throws:
      FileSystemException - On error getting this file's content.
      IOException - On error getting this file's content.
      Since:
      2.4
    • writeContent

      public static void writeContent(FileObject srcFile, FileObject destFile) throws IOException
      Writes the content from a source file to a destination file.
      Parameters:
      srcFile - The source FileObject.
      destFile - The target FileObject
      Throws:
      IOException - If an error occurs copying the file.
      Since:
      2.6.0
      See Also:
    • writeContent

      public static void writeContent(FileObject file, OutputStream output) throws IOException
      Writes the content of a file to an OutputStream.
      Parameters:
      file - The FileObject to write.
      output - The OutputStream to write to.
      Throws:
      IOException - if an error occurs writing the file.
      Since:
      2.6.0
      See Also: