Package org.apache.commons.vfs2.util
Class FileObjectUtils
java.lang.Object
org.apache.commons.vfs2.util.FileObjectUtils
Utility methods for
FileObject
.-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
exists
(FileObject fileObject) Null-safe call toFileObject.exists()
.static AbstractFileObject
getAbstractFileObject
(FileObject fileObject) Gets access to the base object even if decorated.static byte[]
Gets the content of a file object, as a byte array.static String
getContentAsString
(FileObject file, String charset) Returns the content of a file as a String.static String
getContentAsString
(FileObject file, Charset charset) Gets the content of a file as a String.static boolean
isInstanceOf
(FileObject fileObject, Class<?> wantedClass) Checks if the given FileObject is instance of given class argument.static Properties
readProperties
(FileObject fileObject) Reads the given file into a newProperties
.static Properties
readProperties
(FileObject fileObject, Properties properties) Reads the given file into a new givenProperties
.static void
writeContent
(FileObject file, OutputStream output) Writes the content of a file to an OutputStream.static void
writeContent
(FileObject srcFile, FileObject destFile) Writes the content from a source file to a destination file.
-
Method Details
-
exists
Null-safe call toFileObject.exists()
.- Parameters:
fileObject
- the file object to test, may be null.- Returns:
- false if
fileObject
is null, otherwise, seeFileObject.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
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
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
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 newProperties
.- 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 givenProperties
.- Parameters:
fileObject
- the file to readproperties
- 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
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
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:
-