public class VFSUtils extends Object
Constructor and Description |
---|
VFSUtils()
Constructor method for i18n purposes only.
|
Modifier and Type | Method and Description |
---|---|
static String |
addMissingCredentials(String uri,
VFSConnection vfsconn)
Convenience to automatically apply user and password defined for a connection.
|
static boolean |
available(org.apache.commons.vfs2.FileObject url)
Safely gets the info if the URL is currently available (like a PING check).
|
static Boolean |
canRead(org.apache.commons.vfs2.FileObject url)
Safely gets the info if the URL can be read.
|
static boolean |
canRead(org.apache.commons.vfs2.FileObject url,
boolean fallback)
Safely gets the info if the URL can be read.
|
static Boolean |
canWrite(org.apache.commons.vfs2.FileObject url)
Safely gets the info if the URL can be written.
|
static boolean |
canWrite(org.apache.commons.vfs2.FileObject url,
boolean fallback)
Safely gets the info if the URL can be written.
|
static void |
clearDirectory(org.apache.commons.vfs2.FileObject target)
Tries to remove all directories and files from a given directory.
|
static void |
collectEntries(org.apache.commons.vfs2.FileObject searchdir,
Vector<org.apache.commons.vfs2.FileObject> entries)
Searches the given directory recursively for files and directories adds the results to the
container.
|
static boolean |
compareContents(org.apache.commons.vfs2.FileObject url,
File file)
Checks if the given network file contents is equal to the given local file.
|
static boolean |
contains(Vector<org.apache.commons.vfs2.FileObject> container,
org.apache.commons.vfs2.FileObject url)
Checks, if the given container holds the given URL.
|
static String |
debugPrint(org.apache.commons.vfs2.FileSystemOptions options)
Prints file system specific options for a connection.
|
static String |
debugPrintFileName(org.apache.commons.vfs2.FileObject url)
Provides a name without passwords to be displayed, logged etc.
|
static boolean |
delete(org.apache.commons.vfs2.FileObject target)
Tries to delete the given network file/directory (directory must be empty).
|
static void |
deleteAll(org.apache.commons.vfs2.FileObject target)
Tries to delete the given network directory recursively.
|
static Boolean |
exists(org.apache.commons.vfs2.FileObject url)
Safely gets the info if the URL exists.
|
static boolean |
exists(org.apache.commons.vfs2.FileObject url,
boolean fallback)
Safely gets the info if the URL exists.
|
static VFSConnection |
findVFSConnection(VFSFileSystemManager vfsmanager,
String id)
Determines the VFS connection associated with the given ID.
|
static VFSConnection[] |
findVFSConnections(VFSFileSystemManager vfsmanager,
org.apache.commons.vfs2.FileObject entry)
Determines the VFS connections which can be used to show the given network file.
|
static VFSConnection[] |
findVFSConnections(VFSFileSystemManager vfsmanager,
String url)
Determines the VFS connections which can be used to show the given network file.
|
static String |
getCapabilityDescription(org.apache.commons.vfs2.Capability capa)
Provides the user language description of the given file system capability.
|
static org.apache.commons.vfs2.FileObject[] |
getChildren(org.apache.commons.vfs2.FileObject directory)
Provides the children found in a directory.
|
static org.apache.commons.vfs2.FileObject[] |
getChildren(org.apache.commons.vfs2.FileObject directory,
org.apache.commons.vfs2.FileObject[] fallback)
Provides the children found in a directory.
|
static int |
getDefaultPort(String protocol)
Provides the numerical port number appropriate for the given VFS protocol/scheme.
|
static String |
getDisplayBaseName(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
Provides the base name of the given URL (without path, credentials etc.).
|
static String |
getDisplayPath(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
Provides the path of the given URL.
|
static String |
getDisplayURIObfuscated(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static String |
getDisplayURIUsernameOnly(org.apache.commons.vfs2.FileObject entry,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static String |
getDisplayURIUsernameOnly(String url,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static String |
getDisplayURIUsernameOnly(VFSURI entry,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static String |
getDisplayURIWithoutCredentials(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static String |
getDisplayURIWithoutCredentials(VFSURI vfsuri,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static File |
getDownloadFile(File directory,
org.apache.commons.vfs2.FileObject url)
Assembles the preferred target file name for downloads.
|
static String |
getDRWX(org.apache.commons.vfs2.FileObject url)
Generates the accessibility string ("drwx") for files and directories.
|
static Comparator<org.apache.commons.vfs2.FileObject> |
getFileObjectComparator()
Creates a new comparator used together with
TreeMap to handle FileObject 's properly. |
static Long |
getLength(org.apache.commons.vfs2.FileObject url)
Safely gets the URL content length.
|
static long |
getLength(org.apache.commons.vfs2.FileObject url,
long fallback)
Safely gets the URL content length.
|
static org.apache.commons.vfs2.FileObject |
getParent(org.apache.commons.vfs2.FileObject url)
Safely gets the URL parent folder.
|
static VFSURI |
getParent(VFSURI child)
Provides the parent directory of the given URL.
|
static Vector<org.apache.commons.vfs2.FileObject> |
getParents(org.apache.commons.vfs2.FileObject url)
Extracts the parent paths of the given URL.
|
static String |
getProtocol(String uri)
Extracts the scheme part of the given URI.
|
static org.apache.commons.vfs2.FileObject |
getRelativeFileURL(org.apache.commons.vfs2.FileSystemManager vfsmanager,
org.apache.commons.vfs2.FileObject parenturl,
String relpath)
Safely gets the URL assembled of parent and relative path.
|
static String |
getRWX(org.apache.commons.vfs2.FileObject url)
Generates the accessibility string ("rwx") for network files and directories.
|
static org.apache.commons.vfs2.FileType |
getType(org.apache.commons.vfs2.FileObject url)
Safely gets the entry type.
|
static org.apache.commons.vfs2.FileObject |
getURL(org.apache.commons.vfs2.FileSystemManager vfsmanager,
String url)
Creates a VFS network resource object for the given path which should be a URL.
|
static org.apache.commons.vfs2.FileObject |
getURL(VFSFileSystemManager vfsmanager,
String url,
VFSConnection vfsconn)
Creates a VFS network resource object for the given path which should be a URL.
|
static Boolean |
hasCapability(org.apache.commons.vfs2.FileObject url,
org.apache.commons.vfs2.Capability capability)
Safely gets the info if the URL file system has a certain capability.
|
static boolean |
hasCapability(org.apache.commons.vfs2.FileObject url,
org.apache.commons.vfs2.Capability capability,
boolean fallback)
Safely gets the info if the URL file system has a certain capability.
|
static boolean |
hasFileSystemOptions(org.apache.commons.vfs2.FileSystemOptions options)
Any file system specific options available (internal cache not empty)?
|
static boolean |
isChildOf(org.apache.commons.vfs2.FileObject url,
org.apache.commons.vfs2.FileObject parent)
Determines whether the given URL is a child of the given parent.
|
static boolean |
isChildOf(VFSURI url,
VFSURI parent)
Determines whether the given URL is a child of the given parent.
|
static boolean |
isContentLengthRequired(org.apache.commons.vfs2.FileObject url)
Checks if the given protocol requires setting the
VFSLibConstants.ATTR_CONTENT_LENGTH attribute. |
static Boolean |
isDirectory(org.apache.commons.vfs2.FileObject url)
Safely gets the info if the URL is a folder/directory.
|
static boolean |
isDirectory(org.apache.commons.vfs2.FileObject url,
boolean fallback)
Safely gets the info if the URL is a folder/directory.
|
static boolean |
isDirectory(VFSURI vfsuri,
boolean fallback)
Safely gets the info if the URL is a folder/directory.
|
static boolean |
isExistingFile(org.apache.commons.vfs2.FileObject url)
Convenience to check if a given URL exists and is a regular file.
|
static Boolean |
isFile(org.apache.commons.vfs2.FileObject url)
Safely gets the info if the URL is a file.
|
static boolean |
isFile(org.apache.commons.vfs2.FileObject url,
boolean fallback)
Safely gets the info if the URL is a file.
|
static boolean |
isFile(VFSURI vfsuri,
boolean fallback)
Safely gets the info if the URL is a file.
|
static boolean |
isParentOf(org.apache.commons.vfs2.FileObject url,
org.apache.commons.vfs2.FileObject child)
Determines whether the given URL is a the parent of the given child.
|
static boolean |
isRoot(org.apache.commons.vfs2.FileObject url)
Checks if the given URL is a root directory.
|
static boolean |
isSameServer(org.apache.commons.vfs2.FileObject url1,
org.apache.commons.vfs2.FileObject url2)
Checks if the given network files are on the same server.
|
static boolean |
isStateful(String protocol)
Is the given VFS protocol/scheme stateful?
|
static Long |
lastModified(org.apache.commons.vfs2.FileObject url)
Safely gets the URL's last modifcation time.
|
static long |
lastModified(org.apache.commons.vfs2.FileObject url,
long fallback)
Safely gets the URL's last modifcation time.
|
static boolean |
moveToArchive(org.apache.commons.vfs2.FileObject source,
String subfolder)
Moves the given network file into the archive subfolder.
|
static InputStream |
openCachedURL(org.apache.commons.vfs2.FileObject url,
TreeMap<org.apache.commons.vfs2.FileObject,byte[]> urlcache,
long maxsize)
Opens an input stream to read URL data either from cache or directly.
|
static void |
setLastModified(org.apache.commons.vfs2.FileObject url,
long timestamp)
Safely sets the URL's last modifcation time.
|
static boolean |
writeFile(org.apache.commons.vfs2.FileObject url,
InputStream istream,
long length)
Writes binary data into a network file.
|
public VFSUtils() throws InstantiationException
InstantiationException
- Error indicationpublic static Long getLength(org.apache.commons.vfs2.FileObject url)
url
- The network resource to checknull
if not availablepublic static long getLength(org.apache.commons.vfs2.FileObject url, long fallback)
url
- The network resource to checkfallback
- The default valuenull
if not availablepublic static Long lastModified(org.apache.commons.vfs2.FileObject url)
url
- The network resource to checknull
if not availablepublic static long lastModified(org.apache.commons.vfs2.FileObject url, long fallback)
url
- The network resource to checkfallback
- The default valuenull
if not availablepublic static void setLastModified(org.apache.commons.vfs2.FileObject url, long timestamp)
url
- The network resource to checktimestamp
- The timestamppublic static Boolean isDirectory(org.apache.commons.vfs2.FileObject url)
url
- The network resource to checknull
if not available.public static boolean isDirectory(org.apache.commons.vfs2.FileObject url, boolean fallback)
url
- The network resource to checkfallback
- The default valuenull
if not available.public static boolean isDirectory(VFSURI vfsuri, boolean fallback)
vfsuri
- The network resource to checkfallback
- The default valuenull
if not available.public static Boolean isFile(org.apache.commons.vfs2.FileObject url)
url
- The network resource to checknull
if not available.public static boolean isFile(org.apache.commons.vfs2.FileObject url, boolean fallback)
url
- The network resource to checkfallback
- The default valuenull
if not available.public static boolean isFile(VFSURI vfsuri, boolean fallback)
vfsuri
- The network resource to checkfallback
- The default valuenull
if not available.public static org.apache.commons.vfs2.FileType getType(org.apache.commons.vfs2.FileObject url)
url
- The network resource to checknull
if not available.public static Boolean exists(org.apache.commons.vfs2.FileObject url)
url
- The network resource to checknull
if not available.public static boolean exists(org.apache.commons.vfs2.FileObject url, boolean fallback)
url
- The network resource to checkfallback
- The default valuenull
if not available.public static Boolean canRead(org.apache.commons.vfs2.FileObject url)
url
- The network resource to checknull
if not available.public static boolean canRead(org.apache.commons.vfs2.FileObject url, boolean fallback)
url
- The network resource to checkfallback
- The default valuenull
if not available.public static Boolean canWrite(org.apache.commons.vfs2.FileObject url)
url
- The network resource to checknull
if not available.public static boolean canWrite(org.apache.commons.vfs2.FileObject url, boolean fallback)
url
- The network resource to checkfallback
- The default valuenull
if not available.public static Boolean hasCapability(org.apache.commons.vfs2.FileObject url, org.apache.commons.vfs2.Capability capability)
url
- The network resource to checkcapability
- The capabilitynull
if not available.public static boolean hasCapability(org.apache.commons.vfs2.FileObject url, org.apache.commons.vfs2.Capability capability, boolean fallback)
url
- The network resource to checkcapability
- The capabilityfallback
- The default valuenull
if not available.public static org.apache.commons.vfs2.FileObject getParent(org.apache.commons.vfs2.FileObject url)
url
- The network resource to checknull
if not availablepublic static org.apache.commons.vfs2.FileObject getRelativeFileURL(org.apache.commons.vfs2.FileSystemManager vfsmanager, org.apache.commons.vfs2.FileObject parenturl, String relpath)
vfsmanager
- The file system manager, use default if null
parenturl
- The parental network resource (folder)relpath
- The relative pathnull
if not availablepublic static File getDownloadFile(File directory, org.apache.commons.vfs2.FileObject url)
directory
- The target directoryurl
- The network resource to downloadnull
if not availablepublic static InputStream openCachedURL(org.apache.commons.vfs2.FileObject url, TreeMap<org.apache.commons.vfs2.FileObject,byte[]> urlcache, long maxsize)
Caution: Do not use Hashtable
This method works well for SFTP but not for FTP.
Special server encodings are converted here if the connection is specified.
Special server encodings are converted here if the connection is specified.
Remember that exception stack traces also may contain passwords as clear text!
Special server encodings are converted here if the connection is specified.
This variant shows the username if it is available, but never the password.
Special server encodings are converted here if the connection is specified.
This variant shows the username if it is available, but never the password.
Special server encodings are converted here if the connection is specified.
This variant shows the username if it is available, but never the password.
Special server encodings are converted here if the connection is specified.
Remember that exception stack traces also may contain passwords as clear text!
Special server encodings are converted here if the connection is specified.
Remember that exception stack traces also may contain passwords as clear text!
Special server encodings are converted here if the connection is specified.
Since
Since
Use this method with care since all entries are removed recursively without transferring
them into the Windows system garbage or so!
The search directory itself is NOT included!
This is a workaround since
The connection must be available (scheme supported) and applicable for the given URL
(host, credentials etc. must match).
The connection must be available (scheme supported) and applicable for the given URL
(host, credentials etc. must match).
Should be checked when the
Stateful measn that a connection requires a session to be established and closed.
For example, FTP and SFTP are stateful protocols, while HTTP is not.
Caution: Do not use Hashtable
This attribute is known to be required for proper file handling with the Amazon S3 provider.
url
- The network resource to checkurlcache
- The download cachemaxsize
- The maximum file size to be cachednull
if not available
getURL
public static org.apache.commons.vfs2.FileObject getURL(org.apache.commons.vfs2.FileSystemManager vfsmanager,
String url)
vfsmanager
- The file system manager, use default if null
url
- The network resource pathnull
if not available
getURL
public static org.apache.commons.vfs2.FileObject getURL(VFSFileSystemManager vfsmanager,
String url,
VFSConnection vfsconn)
vfsmanager
- The file system manager, use default if null
url
- The network resource pathvfsconn
- The connection (optional, best guess otherwise)null
if not available
available
public static boolean available(org.apache.commons.vfs2.FileObject url)
url
- The network resource to check
isChildOf
public static boolean isChildOf(org.apache.commons.vfs2.FileObject url,
org.apache.commons.vfs2.FileObject parent)
url
- The URL to be checkedparent
- The parent URL to be checked
isChildOf
public static boolean isChildOf(VFSURI url,
VFSURI parent)
url
- The URL to be checkedparent
- The parent URL to be checked
getParent
public static VFSURI getParent(VFSURI child)
child
- The child URLnull
for root
getRWX
public static String getRWX(org.apache.commons.vfs2.FileObject url)
url
- The URL to be checked
getDRWX
public static String getDRWX(org.apache.commons.vfs2.FileObject url)
url
- The URL to be checked
getDisplayBaseName
public static String getDisplayBaseName(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
url
- The URLvfsconn
- The connection for encoding (optional)
getDisplayPath
public static String getDisplayPath(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
url
- The URLvfsconn
- The connection for encoding (optional)
getDisplayURIObfuscated
public static String getDisplayURIObfuscated(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
url
- The URLvfsconn
- The connection for encoding (optional)
getDisplayURIUsernameOnly
public static String getDisplayURIUsernameOnly(org.apache.commons.vfs2.FileObject entry,
VFSConnection vfsconn)
entry
- The URLvfsconn
- The connection for encoding (optional)
getDisplayURIUsernameOnly
public static String getDisplayURIUsernameOnly(VFSURI entry,
VFSConnection vfsconn)
entry
- The URLvfsconn
- The connection for encoding (optional)
getDisplayURIUsernameOnly
public static String getDisplayURIUsernameOnly(String url,
VFSConnection vfsconn)
url
- The URLvfsconn
- The connection for encoding (optional)
getDisplayURIWithoutCredentials
public static String getDisplayURIWithoutCredentials(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
url
- The URLvfsconn
- The connection for encoding (optional)
getDisplayURIWithoutCredentials
public static String getDisplayURIWithoutCredentials(VFSURI vfsuri,
VFSConnection vfsconn)
vfsuri
- The URLvfsconn
- The connection for encoding (optional)
debugPrintFileName
public static String debugPrintFileName(org.apache.commons.vfs2.FileObject url)
url
- The URL
isParentOf
public static boolean isParentOf(org.apache.commons.vfs2.FileObject url,
org.apache.commons.vfs2.FileObject child)
url
- The URL to be checkedchild
- The child URL to be checkedNullPointerException
- If a parameter is null
getParents
public static Vector<org.apache.commons.vfs2.FileObject> getParents(org.apache.commons.vfs2.FileObject url)
url
- The URL to be checkedNullPointerException
- If the file is null
getCapabilityDescription
public static String getCapabilityDescription(org.apache.commons.vfs2.Capability capa)
capa
- The capability valuenull
otherwise
getChildren
public static org.apache.commons.vfs2.FileObject[] getChildren(org.apache.commons.vfs2.FileObject directory)
throws org.apache.commons.vfs2.FileSystemException
FileObject.getChildren()
may take very long, this method warns with a stack
trace if this code is called from the event displatch thread. Application developers
should call this method instead of FileObject.getChildren()
to be warned.
directory
- The directoryorg.apache.commons.vfs2.FileSystemException
- If an error occurs
getChildren
public static org.apache.commons.vfs2.FileObject[] getChildren(org.apache.commons.vfs2.FileObject directory,
org.apache.commons.vfs2.FileObject[] fallback)
FileObject.getChildren()
may take very long, this method warns with a stack
trace if this code is called from the event displatch thread. Application developers
should call this method instead of FileObject.getChildren()
to be warned.
directory
- The directoryfallback
- The default value
isRoot
public static boolean isRoot(org.apache.commons.vfs2.FileObject url)
url
- The directory
clearDirectory
public static void clearDirectory(org.apache.commons.vfs2.FileObject target)
target
- The directory to be clearedNullPointerException
- If parameters are null
collectEntries
public static void collectEntries(org.apache.commons.vfs2.FileObject searchdir,
Vector<org.apache.commons.vfs2.FileObject> entries)
searchdir
- The directory to begin searchingentries
- Container with paths (File
)
isExistingFile
public static boolean isExistingFile(org.apache.commons.vfs2.FileObject url)
url
- The URL to be checkedNullPointerException
- If the URL is null
writeFile
public static boolean writeFile(org.apache.commons.vfs2.FileObject url,
InputStream istream,
long length)
url
- Network file to be writtenistream
- Binary data streamlength
- Number of bytes to write, -1 = unknown
contains
public static boolean contains(Vector<org.apache.commons.vfs2.FileObject> container,
org.apache.commons.vfs2.FileObject url)
FileObject.equals()
does not properly detect
identical entries properly. Here, the text representations are checked instead.
container
- The URL seturl
- The URL to be checkedNullPointerException
- If the file is null
delete
public static boolean delete(org.apache.commons.vfs2.FileObject target)
target
- The directory to be removedNullPointerException
- If parameters are null
deleteAll
public static void deleteAll(org.apache.commons.vfs2.FileObject target)
target
- The directory to be removedNullPointerException
- If parameters are null
moveToArchive
public static boolean moveToArchive(org.apache.commons.vfs2.FileObject source,
String subfolder)
source
- File to be movedsubfolder
- Defaults to "ARCHIVE"NullPointerException
- If parameters are null
hasFileSystemOptions
public static boolean hasFileSystemOptions(org.apache.commons.vfs2.FileSystemOptions options)
options
- The options to check
debugPrint
public static String debugPrint(org.apache.commons.vfs2.FileSystemOptions options)
options
- The options to check
findVFSConnection
public static VFSConnection findVFSConnection(VFSFileSystemManager vfsmanager,
String id)
vfsmanager
- The managerid
- The connection IDnull
if not available
findVFSConnections
public static VFSConnection[] findVFSConnections(VFSFileSystemManager vfsmanager,
org.apache.commons.vfs2.FileObject entry)
vfsmanager
- The managerentry
- The URLnull
if not available
findVFSConnections
public static VFSConnection[] findVFSConnections(VFSFileSystemManager vfsmanager,
String url)
vfsmanager
- The managerurl
- The URLnull
if not available
addMissingCredentials
public static String addMissingCredentials(String uri,
VFSConnection vfsconn)
uri
- The URI to resolvevfsconn
- The connection with optionsuri
parameter otherwise
isSameServer
public static boolean isSameServer(org.apache.commons.vfs2.FileObject url1,
org.apache.commons.vfs2.FileObject url2)
FileObject.moveTo()
feature is to be used.
url1
- The first network fileurl2
- The second network fileuri
parameter otherwise
isStateful
public static boolean isStateful(String protocol)
protocol
- The VFS scheme/protocol like "sftp"
getProtocol
public static String getProtocol(String uri)
uri
- The URI to parsenull
otherwise
getDefaultPort
public static int getDefaultPort(String protocol)
protocol
- The VFS scheme/protocol like "sftp"
getFileObjectComparator
public static Comparator<org.apache.commons.vfs2.FileObject> getFileObjectComparator()
TreeMap
to handle FileObject
's properly.
isContentLengthRequired
public static boolean isContentLengthRequired(org.apache.commons.vfs2.FileObject url)
VFSLibConstants.ATTR_CONTENT_LENGTH
attribute.
url
- The network fileNullPointerException
- If a parameter is null
compareContents
public static boolean compareContents(org.apache.commons.vfs2.FileObject url,
File file)
url
- The network filefile
- The local fileNullPointerException
- If a parameter is null
Copyright © 2005-2024 Leisenfels GmbH. All rights reserved.