public class VFSUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_SIZE
The default buffer size to use for copies
|
private static java.lang.String |
DEFAULT_ENCODING
The default encoding
|
private static java.io.InputStream |
EMPTY_STREAM |
static java.net.URLStreamHandler |
FILE_URL_HANDLER
The
URLStreamHandler for the 'file' protocol |
static java.lang.String |
FORCE_CASE_SENSITIVE_KEY
Constant representing the system property for forcing case sensitive
|
private static boolean |
forceCaseSensitive
This variable indicates if the FileSystem should force case sensitive independently if
the underlying file system is case sensitive or not
|
private static java.util.regex.Pattern |
GLOB_PATTERN |
static java.lang.String |
VFS_PROTOCOL
Constant representing the URL vfs protocol
|
static java.net.URLStreamHandler |
VFS_URL_HANDLER
The
URLStreamHandler for the 'vfs' protocol |
| Modifier | Constructor and Description |
|---|---|
private |
VFSUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addManifestLocations(VirtualFile file,
java.util.List<VirtualFile> paths)
Add manifest paths
|
static java.lang.String |
canonicalize(java.lang.String path)
Canonicalize the given path.
|
static void |
copyChildrenRecursive(VirtualFile original,
VirtualFile target)
Copy all the children from the original
VirtualFile the target recursively. |
static void |
copyStream(java.io.InputStream is,
java.io.OutputStream os)
Copy input stream to output stream without closing streams.
|
static void |
copyStream(java.io.InputStream is,
java.io.OutputStream os,
int bufferSize)
Copy input stream to output stream without closing streams.
|
static void |
copyStreamAndClose(java.io.InputStream is,
java.io.OutputStream os)
Copy input stream to output stream and close them both
|
static void |
copyStreamAndClose(java.io.InputStream is,
java.io.OutputStream os,
int bufferSize)
Copy input stream to output stream and close them both
|
static java.io.InputStream |
createJarFileInputStream(VirtualFile virtualFile)
Get an input stream that will always be consumable as a Zip/Jar file.
|
static java.lang.String |
decode(java.lang.String path)
Decode the path with UTF-8 encoding..
|
static java.lang.String |
decode(java.lang.String path,
java.lang.String encoding)
Decode the path.
|
static java.io.InputStream |
emptyStream()
Get the empty input stream.
|
static boolean |
exists(java.io.File file)
In case the file system is not case sensitive we compare the canonical path with
the absolute path of the file after normalized.
|
static java.lang.String |
fixName(java.lang.String name)
Fix a name (removes any trailing slash)
|
static java.util.regex.Pattern |
getGlobPattern(java.lang.String glob)
Get a regular expression pattern which matches any path names which match the given glob.
|
static java.util.jar.Manifest |
getManifest(VirtualFile archive)
Get a manifest from a virtual file, assuming the virtual file is the root of an archive
|
static java.io.File |
getMountSource(java.io.Closeable handle)
Return the mount source File for a given mount handle.
|
static java.lang.String |
getName(java.net.URI uri)
Get the name.
|
static java.lang.String |
getPathsString(java.util.Collection<VirtualFile> paths)
Get the paths string for a collection of virtual files
|
static java.net.URI |
getPhysicalURI(VirtualFile file)
Get a physical URI for a virtual file.
|
static java.net.URL |
getPhysicalURL(VirtualFile file)
Get a physical URL for a virtual file.
|
static java.net.URI |
getRootURI(VirtualFile file)
Get the physical root URL of the filesystem of a virtual file.
|
static java.net.URL |
getRootURL(VirtualFile file)
Get the physical root URL of the filesystem of a virtual file.
|
static java.net.URI |
getVirtualURI(VirtualFile file)
Get the virtual URI for a virtual file.
|
static java.net.URL |
getVirtualURL(VirtualFile file)
Get the virtual URL for a virtual file.
|
static boolean |
isForceCaseSensitive() |
static java.util.jar.Manifest |
readManifest(VirtualFile manifest)
Read the manifest from given manifest VirtualFile.
|
static void |
recursiveCopy(java.io.File original,
java.io.File destDir)
Recursively copy a file or directory from one location to another.
|
static void |
recursiveCopy(java.io.File original,
VirtualFile destDir)
Recursively copy a file or directory from one location to another.
|
static void |
recursiveCopy(VirtualFile original,
java.io.File destDir)
Recursively copy a file or directory from one location to another.
|
static void |
recursiveCopy(VirtualFile original,
VirtualFile destDir)
Recursively copy a file or directory from one location to another.
|
static boolean |
recursiveDelete(java.io.File root)
Attempt to recursively delete a real file.
|
static boolean |
recursiveDelete(VirtualFile root)
Attempt to recursively delete a virtual file.
|
static void |
safeClose(java.io.Closeable... closeables)
Safely close some resource without throwing an exception.
|
static void |
safeClose(java.io.Closeable c)
Safely close some resource without throwing an exception.
|
static void |
safeClose(java.lang.Iterable<? extends java.io.Closeable> ci)
Safely close some resources without throwing an exception.
|
static void |
safeClose(java.util.zip.ZipFile zipFile)
Safely close some resource without throwing an exception.
|
static java.net.URL |
sanitizeURL(java.net.URL url)
Ensure the url is convertible to URI by encoding spaces and percent characters if necessary
|
static java.net.URI |
toURI(java.net.URL url)
Deal with urls that may include spaces.
|
static void |
unzip(java.io.File zipFile,
java.io.File destDir)
Expand a zip file to a destination directory.
|
static void |
writeFile(VirtualFile virtualFile,
byte[] bytes)
Write the given bytes to the given virtual file, replacing its current contents (if any) or creating a new file if
one does not exist.
|
static void |
writeFile(VirtualFile virtualFile,
java.io.InputStream is)
Write the content from the given
InputStream to the given virtual file, replacing its current contents (if any) or creating a new file if
one does not exist. |
private static final java.lang.String DEFAULT_ENCODING
public static final java.lang.String VFS_PROTOCOL
public static final java.lang.String FORCE_CASE_SENSITIVE_KEY
public static final java.net.URLStreamHandler VFS_URL_HANDLER
URLStreamHandler for the 'vfs' protocolpublic static final java.net.URLStreamHandler FILE_URL_HANDLER
URLStreamHandler for the 'file' protocolpublic static final int DEFAULT_BUFFER_SIZE
private static boolean forceCaseSensitive
private static final java.io.InputStream EMPTY_STREAM
private static final java.util.regex.Pattern GLOB_PATTERN
public static java.lang.String getPathsString(java.util.Collection<VirtualFile> paths)
paths - the pathsjava.lang.IllegalArgumentException - for null pathspublic static void addManifestLocations(VirtualFile file, java.util.List<VirtualFile> paths) throws java.io.IOException
file - the filepaths - the paths to add tojava.io.IOException - if there is an error reading the manifest or the virtual file is closedjava.lang.IllegalStateException - if the file has no parentjava.lang.IllegalArgumentException - for a null file or pathspublic static java.util.jar.Manifest getManifest(VirtualFile archive) throws java.io.IOException
archive - the root the archivejava.io.IOException - if there is an error reading the manifest or the virtual file is closedjava.lang.IllegalArgumentException - for a null archivepublic static java.util.jar.Manifest readManifest(VirtualFile manifest) throws java.io.IOException
manifest - the VF to read fromjava.io.IOException - if problems while opening VF stream occurpublic static java.lang.String fixName(java.lang.String name)
name - the name to fixjava.lang.IllegalArgumentException - for a null namepublic static java.lang.String decode(java.lang.String path)
path - the path to decodepublic static java.lang.String decode(java.lang.String path,
java.lang.String encoding)
path - the path to decodeencoding - the encodingpublic static java.lang.String getName(java.net.URI uri)
uri - the uripublic static java.net.URI toURI(java.net.URL url)
throws java.net.URISyntaxException
url - the urljava.net.URISyntaxException - for any errorpublic static java.net.URL sanitizeURL(java.net.URL url)
throws java.net.URISyntaxException,
java.net.MalformedURLException
url - to be sanitizedjava.net.URISyntaxException - if URI conversion can't be fixedjava.net.MalformedURLException - if an error occurspublic static void copyChildrenRecursive(VirtualFile original, VirtualFile target) throws java.io.IOException
VirtualFile the target recursively.original - the file to copy children fromtarget - the file to copy the children tojava.io.IOException - if any problems occur copying the filespublic static void copyStreamAndClose(java.io.InputStream is,
java.io.OutputStream os)
throws java.io.IOException
is - input streamos - output streamjava.io.IOException - for any errorpublic static void copyStreamAndClose(java.io.InputStream is,
java.io.OutputStream os,
int bufferSize)
throws java.io.IOException
is - input streamos - output streambufferSize - the buffer size to usejava.io.IOException - for any errorpublic static void copyStream(java.io.InputStream is,
java.io.OutputStream os)
throws java.io.IOException
is - input streamos - output streamjava.io.IOException - for any errorpublic static void copyStream(java.io.InputStream is,
java.io.OutputStream os,
int bufferSize)
throws java.io.IOException
is - input streamos - output streambufferSize - the buffer size to usejava.io.IOException - for any errorpublic static void writeFile(VirtualFile virtualFile, byte[] bytes) throws java.io.IOException
virtualFile - the virtual file to writebytes - the bytesjava.io.IOException - if an error occurspublic static void writeFile(VirtualFile virtualFile, java.io.InputStream is) throws java.io.IOException
InputStream to the given virtual file, replacing its current contents (if any) or creating a new file if
one does not exist.virtualFile - the virtual file to writeis - the input streamjava.io.IOException - if an error occurspublic static java.net.URL getVirtualURL(VirtualFile file) throws java.net.MalformedURLException
File class may fail if the file is not present
on the physical filesystem, and in general should not be attempted.
Note: if the given VirtualFile refers to a directory at the time of this
method invocation, a trailing slash will be appended to the URL; this means that invoking
this method may require a filesystem access, and in addition, may not produce consistent results
over time.file - the virtual filejava.net.MalformedURLException - if the file cannot be coerced into a URL for some reasonVirtualFile.asDirectoryURL(),
VirtualFile.asFileURL()public static java.net.URI getVirtualURI(VirtualFile file) throws java.net.URISyntaxException
file - the virtual filejava.net.URISyntaxException - if the file cannot be coerced into a URI for some reasonVirtualFile.asDirectoryURI(),
VirtualFile.asFileURI()public static java.net.URL getPhysicalURL(VirtualFile file) throws java.io.IOException
VirtualFile.getPhysicalFile() method
before using this method.file - the virtual filejava.io.IOException - if an I/O error occurs getting the physical filepublic static java.net.URI getPhysicalURI(VirtualFile file) throws java.io.IOException
VirtualFile.getPhysicalFile() method
before using this method.file - the virtual filejava.io.IOException - if an I/O error occurs getting the physical filepublic static java.net.URL getRootURL(VirtualFile file) throws java.net.MalformedURLException
jar and file) are supported.file - the virtual filejava.net.MalformedURLException - if the URL is not validpublic static java.net.URI getRootURI(VirtualFile file) throws java.net.URISyntaxException
jar and file) are supported.file - the virtual filejava.net.URISyntaxException - if the URI is not validpublic static void safeClose(java.io.Closeable c)
c - the resourcepublic static void safeClose(java.io.Closeable... closeables)
closeables - the resourcespublic static void safeClose(java.lang.Iterable<? extends java.io.Closeable> ci)
ci - the resourcespublic static void safeClose(java.util.zip.ZipFile zipFile)
zipFile - the resourcepublic static boolean isForceCaseSensitive()
public static boolean exists(java.io.File file)
file - public static boolean recursiveDelete(java.io.File root)
root - the real file to deletetrue if the file was deletedpublic static boolean recursiveDelete(VirtualFile root)
root - the virtual file to deletetrue if the file was deletedpublic static void recursiveCopy(java.io.File original,
java.io.File destDir)
throws java.io.IOException
original - the original file or directorydestDir - the destination directoryjava.io.IOException - if an I/O error occurs before the copy is completepublic static void recursiveCopy(java.io.File original,
VirtualFile destDir)
throws java.io.IOException
original - the original file or directorydestDir - the destination directoryjava.io.IOException - if an I/O error occurs before the copy is completepublic static void recursiveCopy(VirtualFile original, java.io.File destDir) throws java.io.IOException
original - the original virtual file or directorydestDir - the destination directoryjava.io.IOException - if an I/O error occurs before the copy is completepublic static void recursiveCopy(VirtualFile original, VirtualFile destDir) throws java.io.IOException
original - the original virtual file or directorydestDir - the destination virtual directoryjava.io.IOException - if an I/O error occurs before the copy is completepublic static java.io.InputStream emptyStream()
public static java.io.InputStream createJarFileInputStream(VirtualFile virtualFile) throws java.io.IOException
virtualFile - The virtual to get a jar file input stream forjava.io.IOException - if any problems occurpublic static void unzip(java.io.File zipFile,
java.io.File destDir)
throws java.io.IOException
zipFile - the zip filedestDir - the destination directoryjava.io.IOException - if an error occurspublic static java.io.File getMountSource(java.io.Closeable handle)
handle - The handle to get the source forpublic static java.util.regex.Pattern getGlobPattern(java.lang.String glob)
ant file patterns. Valid meta-characters in the glob pattern include:
"\" - escape the next character (treat it literally, even if it is itself a recognized meta-character)"?" - match any non-slash character"*" - match zero or more non-slash characters"**" - match zero or more characters, including slashes"/" - match one or more slash characters. Consecutive / characters are collapsed down into one.ant, if the pattern ends with a /, then an implicit "**" will be appended.
See also: "Patterns" in the Ant Manualglob - the glob to matchpublic static java.lang.String canonicalize(java.lang.String path)
. and .. segments from the path.path - the relative or absolute possibly non-canonical path