Package org.apache.commons.vfs2.util
Class FileObjectUtils
- java.lang.Object
-
- org.apache.commons.vfs2.util.FileObjectUtils
-
public final class FileObjectUtils extends java.lang.Object
Utility methods forFileObject
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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[]
getContentAsByteArray(FileObject file)
Gets the content of a file object, as a byte array.static java.lang.String
getContentAsString(FileObject file, java.lang.String charset)
Returns the content of a file as a String.static java.lang.String
getContentAsString(FileObject file, java.nio.charset.Charset charset)
Gets the content of a file as a String.static boolean
isInstanceOf(FileObject fileObject, java.lang.Class<?> wantedClass)
Checks if the given FileObject is instance of given class argument.static java.util.Properties
readProperties(FileObject fileObject)
Reads the given file into a newProperties
.static java.util.Properties
readProperties(FileObject fileObject, java.util.Properties properties)
Reads the given file into a new givenProperties
.static void
writeContent(FileObject file, java.io.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 Detail
-
exists
public static boolean exists(FileObject fileObject) throws FileSystemException
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
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 newProperties
.- 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 givenProperties
.- Parameters:
fileObject
- the file to readproperties
- 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)
-
-