public final class VFSUtils
extends java.lang.Object
Constructor and Description |
---|
VFSUtils()
Constructor method for i18n purposes only.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addMissingCredentials(java.lang.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 java.lang.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 java.lang.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,
java.util.Vector<org.apache.commons.vfs2.FileObject> entries)
Searches the given directory recursively for files and directories adds the results to the
container.
|
static boolean |
contains(java.util.Vector<org.apache.commons.vfs2.FileObject> container,
org.apache.commons.vfs2.FileObject url)
Checks, if the given container holds the given URL.
|
static java.lang.String |
debugPrint(org.apache.commons.vfs2.FileSystemOptions options)
Prints file system specific options for a connection.
|
static java.lang.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.
|
static java.lang.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,
java.lang.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,
java.lang.String url)
Determines the VFS connections which can be used to show the given network file.
|
static java.lang.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(java.lang.String protocol)
Provides the numerical port number appropriate for the given VFS protocol/scheme.
|
static java.lang.String |
getDisplayBaseName(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
Provides the base name of the given URL (without path, credentials etc.).
|
static java.lang.String |
getDisplayPath(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
Provides the path of the given URL.
|
static java.lang.String |
getDisplayURIObfuscated(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static java.lang.String |
getDisplayURIUsernameOnly(org.apache.commons.vfs2.FileObject entry,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static java.lang.String |
getDisplayURIUsernameOnly(java.lang.String url,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static java.lang.String |
getDisplayURIUsernameOnly(VFSURI entry,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static java.lang.String |
getDisplayURIWithoutCredentials(org.apache.commons.vfs2.FileObject url,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static java.lang.String |
getDisplayURIWithoutCredentials(VFSURI vfsuri,
VFSConnection vfsconn)
Provides a name without passwords to be displayed, logged etc.
|
static java.io.File |
getDownloadFile(java.io.File directory,
org.apache.commons.vfs2.FileObject url)
Assembles the preferred target file name for downloads.
|
static java.lang.String |
getDRWX(org.apache.commons.vfs2.FileObject url)
Generates the accessibility string ("drwx") for files and directories.
|
static org.apache.commons.vfs2.FileObject |
getDummyURL()
Creates a VFS network resource object which always exists (e.g. local user's home).
|
static org.apache.commons.vfs2.FileObject |
getDummyURL(java.lang.String name)
Creates a VFS network resource object which name is empty.
|
static java.lang.String |
getEntryType(org.apache.commons.vfs2.FileObject url,
com.lf.commons.io.FileTypeFactory typefactory)
Determines the type of the given file or directory.
|
static java.lang.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 java.util.Vector<org.apache.commons.vfs2.FileObject> |
getParents(org.apache.commons.vfs2.FileObject url)
Extracts the parent paths of the given URL.
|
static java.lang.String |
getProtocol(java.lang.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,
java.lang.String relpath)
Safely gets the URL assembled of parent and relative path.
|
static java.lang.String |
getRWX(org.apache.commons.vfs2.FileObject url)
Generates the accessibility string ("rwx") for network files and directories.
|
static org.apache.commons.vfs2.FileObject |
getURL(org.apache.commons.vfs2.FileSystemManager vfsmanager,
java.lang.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,
java.lang.String url,
VFSConnection vfsconn)
Creates a VFS network resource object for the given path which should be a URL.
|
static javax.swing.Icon |
getURLIcon(org.apache.commons.vfs2.FileObject url,
com.lf.commons.io.TypeProvider provider)
Tries to determine the icon which the system would use for a downloaded URL.
|
static javax.swing.Icon |
getURLIcon(VFSURI vfsuri,
com.lf.commons.io.TypeProvider provider)
Tries to determine the icon which the system would use for a downloaded URL.
|
static java.lang.String |
getURLType(org.apache.commons.vfs2.FileObject url,
com.lf.commons.io.TypeProvider provider)
Tries to determine the file type which the system would use for a downloaded URL.
|
static java.lang.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 java.lang.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 java.lang.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(java.lang.String protocol)
Is the given VFS protocol/scheme stateful?.
|
static java.lang.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,
java.lang.String subfolder)
Moves the given network file into the archive subfolder.
|
static java.io.InputStream |
openCachedURL(org.apache.commons.vfs2.FileObject url,
java.util.Hashtable<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,
java.io.InputStream istream,
long length)
Writes binary data into a network file.
|
public VFSUtils() throws java.lang.InstantiationException
I18NExtractor
).
java.lang.InstantiationException
- Error indicationpublic static java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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, java.lang.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 java.io.File getDownloadFile(java.io.File directory, org.apache.commons.vfs2.FileObject url)
directory
- The target directoryurl
- The network resource to downloadnull
if not availablepublic static java.io.InputStream openCachedURL(org.apache.commons.vfs2.FileObject url, java.util.Hashtable<org.apache.commons.vfs2.FileObject,byte[]> urlcache, long maxsize)
url
- The network resource to checkurlcache
- The download cachemaxsize
- The maximum file size to be cachednull
if not availablepublic static org.apache.commons.vfs2.FileObject getURL(org.apache.commons.vfs2.FileSystemManager vfsmanager, java.lang.String url)
vfsmanager
- The file system manager, use default if null
url
- The network resource pathnull
if not availablepublic static org.apache.commons.vfs2.FileObject getURL(VFSFileSystemManager vfsmanager, java.lang.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 availablepublic static javax.swing.Icon getURLIcon(org.apache.commons.vfs2.FileObject url, com.lf.commons.io.TypeProvider provider)
TypeProvider
only once.
url
- The URL to be checkedprovider
- The type providernull
public static javax.swing.Icon getURLIcon(VFSURI vfsuri, com.lf.commons.io.TypeProvider provider)
TypeProvider
only once.
vfsuri
- The URL to be checkedprovider
- The type providernull
public static java.lang.String getURLType(org.apache.commons.vfs2.FileObject url, com.lf.commons.io.TypeProvider provider)
TypeProvider
only once.
url
- The URL to be checkedprovider
- The type providernull
public static boolean available(org.apache.commons.vfs2.FileObject url)
url
- The network resource to checkpublic 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 checkedpublic static boolean isChildOf(VFSURI url, VFSURI parent)
url
- The URL to be checkedparent
- The parent URL to be checkedpublic static VFSURI getParent(VFSURI child)
child
- The child URLnull
for rootpublic static org.apache.commons.vfs2.FileObject getDummyURL()
null
public static org.apache.commons.vfs2.FileObject getDummyURL(java.lang.String name)
name
- The configurable name (optional)null
public static java.lang.String getRWX(org.apache.commons.vfs2.FileObject url)
url
- The URL to be checkedpublic static java.lang.String getDRWX(org.apache.commons.vfs2.FileObject url)
url
- The URL to be checkedpublic static java.lang.String getEntryType(org.apache.commons.vfs2.FileObject url, com.lf.commons.io.FileTypeFactory typefactory)
url
- The URL to be checkedtypefactory
- The file type provider (optional)public static java.lang.String getDisplayBaseName(org.apache.commons.vfs2.FileObject url, VFSConnection vfsconn)
url
- The URLvfsconn
- The connection for encoding (optional)public static java.lang.String getDisplayPath(org.apache.commons.vfs2.FileObject url, VFSConnection vfsconn)
url
- The URLvfsconn
- The connection for encoding (optional)public static java.lang.String getDisplayURIObfuscated(org.apache.commons.vfs2.FileObject url, VFSConnection vfsconn)
url
- The URLvfsconn
- The connection for encoding (optional)public static java.lang.String getDisplayURIUsernameOnly(org.apache.commons.vfs2.FileObject entry, VFSConnection vfsconn)
entry
- The URLvfsconn
- The connection for encoding (optional)public static java.lang.String getDisplayURIUsernameOnly(VFSURI entry, VFSConnection vfsconn)
entry
- The URLvfsconn
- The connection for encoding (optional)public static java.lang.String getDisplayURIUsernameOnly(java.lang.String url, VFSConnection vfsconn)
url
- The URLvfsconn
- The connection for encoding (optional)public static java.lang.String getDisplayURIWithoutCredentials(org.apache.commons.vfs2.FileObject url, VFSConnection vfsconn)
url
- The URLvfsconn
- The connection for encoding (optional)public static java.lang.String getDisplayURIWithoutCredentials(VFSURI vfsuri, VFSConnection vfsconn)
vfsuri
- The URLvfsconn
- The connection for encoding (optional)public static java.lang.String debugPrintFileName(org.apache.commons.vfs2.FileObject url)
url
- The URLpublic 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 checkedjava.lang.NullPointerException
- If a parameter is null
public static java.util.Vector<org.apache.commons.vfs2.FileObject> getParents(org.apache.commons.vfs2.FileObject url)
url
- The URL to be checkedjava.lang.NullPointerException
- If the file is null
public static java.lang.String getCapabilityDescription(org.apache.commons.vfs2.Capability capa)
capa
- The capability valuenull
otherwisepublic 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 occurspublic 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 valuepublic static boolean isRoot(org.apache.commons.vfs2.FileObject url)
url
- The directorypublic static void clearDirectory(org.apache.commons.vfs2.FileObject target)
target
- The directory to be clearedjava.lang.NullPointerException
- If parameters are null
public static void collectEntries(org.apache.commons.vfs2.FileObject searchdir, java.util.Vector<org.apache.commons.vfs2.FileObject> entries)
searchdir
- The directory to begin searchingentries
- Container with paths (File
)public static boolean isExistingFile(org.apache.commons.vfs2.FileObject url)
url
- The URL to be checkedjava.lang.NullPointerException
- If the URL is null
public static boolean writeFile(org.apache.commons.vfs2.FileObject url, java.io.InputStream istream, long length)
url
- Network file to be writtenistream
- Binary data streamlength
- Number of bytes to write, -1 = unknownpublic static boolean contains(java.util.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 checkedjava.lang.NullPointerException
- If the file is null
public static boolean delete(org.apache.commons.vfs2.FileObject target)
target
- The directory to be removedjava.lang.NullPointerException
- If parameters are null
public static boolean moveToArchive(org.apache.commons.vfs2.FileObject source, java.lang.String subfolder)
source
- Zu verschiebende Dateisubfolder
- Defaults to "ARCHIVE"java.lang.NullPointerException
- If parameters are null
public static boolean hasFileSystemOptions(org.apache.commons.vfs2.FileSystemOptions options)
options
- The options to checkpublic static java.lang.String debugPrint(org.apache.commons.vfs2.FileSystemOptions options)
options
- The options to checkpublic static VFSConnection findVFSConnection(VFSFileSystemManager vfsmanager, java.lang.String id)
vfsmanager
- The managerid
- The connection IDnull
if not availablepublic static VFSConnection[] findVFSConnections(VFSFileSystemManager vfsmanager, org.apache.commons.vfs2.FileObject entry)
vfsmanager
- The managerentry
- The URLnull
if not availablepublic static VFSConnection[] findVFSConnections(VFSFileSystemManager vfsmanager, java.lang.String url)
vfsmanager
- The managerurl
- The URLnull
if not availablepublic static java.lang.String addMissingCredentials(java.lang.String uri, VFSConnection vfsconn)
uri
- The URI to resolvevfsconn
- The connection with optionsuri
parameter otherwisepublic 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 otherwisepublic static boolean isStateful(java.lang.String protocol)
protocol
- The VFS scheme/protocol like "sftp"public static java.lang.String getProtocol(java.lang.String uri)
uri
- The URI to parsenull
otherwisepublic static int getDefaultPort(java.lang.String protocol)
protocol
- The VFS scheme/protocol like "sftp"Copyright © 2005-2014 Leisenfels UG. All rights reserved.