Class FileObjectUtils

    • Method Detail

      • getContentAsByteArray

        public static byte[] getContentAsByteArray​(FileObject file)
                                            throws java.io.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:
        java.io.IOException - if the file content cannot be accessed.
        Since:
        2.6.0
      • getContentAsString

        public static java.lang.String getContentAsString​(FileObject file,
                                                          java.nio.charset.Charset charset)
                                                   throws java.io.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:
        java.io.IOException - if the file content cannot be accessed.
        Since:
        2.4
      • getContentAsString

        public static java.lang.String getContentAsString​(FileObject file,
                                                          java.lang.String charset)
                                                   throws java.io.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:
        java.io.IOException - if the file content cannot be accessed.
        Since:
        2.4
      • isInstanceOf

        public static boolean isInstanceOf​(FileObject fileObject,
                                           java.lang.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 java.util.Properties readProperties​(FileObject fileObject)
                                                   throws FileSystemException,
                                                          java.io.IOException
        Reads the given file into a new Properties.
        Parameters:
        fileObject - the file to read
        Returns:
        a new Properties.
        Throws:
        java.io.IOException - On error getting this file's content.
        FileSystemException - On error getting this file's content.
        java.io.IOException - On error getting this file's content.
        Since:
        2.4
      • readProperties

        public static java.util.Properties readProperties​(FileObject fileObject,
                                                          java.util.Properties properties)
                                                   throws FileSystemException,
                                                          java.io.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.
        java.io.IOException - On error getting this file's content.
        Since:
        2.4
      • writeContent

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

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