Class VFSUtils
java.lang.Object
org.jboss.vfs.VFSUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default buffer size to use for copiesprivate static final StringThe default encodingprivate static final InputStreamstatic final URLStreamHandlerTheURLStreamHandlerfor the 'file' protocolstatic final StringConstant representing the system property for forcing case sensitiveprivate static booleanThis variable indicates if the FileSystem should force case sensitive independently if the underlying file system is case sensitive or notprivate static final Patternstatic final StringConstant representing the URL vfs protocolstatic final URLStreamHandlerTheURLStreamHandlerfor the 'vfs' protocol -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddManifestLocations(VirtualFile file, List<VirtualFile> paths) Add manifest pathsstatic Stringcanonicalize(String path) Canonicalize the given path.static voidcopyChildrenRecursive(VirtualFile original, VirtualFile target) Copy all the children from the originalVirtualFilethe target recursively.static voidcopyStream(InputStream is, OutputStream os) Copy input stream to output stream without closing streams.static voidcopyStream(InputStream is, OutputStream os, int bufferSize) Copy input stream to output stream without closing streams.static voidCopy input stream to output stream and close them bothstatic voidcopyStreamAndClose(InputStream is, OutputStream os, int bufferSize) Copy input stream to output stream and close them bothstatic InputStreamcreateJarFileInputStream(VirtualFile virtualFile) Get an input stream that will always be consumable as a Zip/Jar file.static StringDecode the path with UTF-8 encoding..static StringDecode the path.static InputStreamGet the empty input stream.static booleanIn case the file system is not case sensitive we compare the canonical path with the absolute path of the file after normalized.static StringFix a name (removes any trailing slash)static PatterngetGlobPattern(String glob) Get a regular expression pattern which matches any path names which match the given glob.static ManifestgetManifest(VirtualFile archive) Get a manifest from a virtual file, assuming the virtual file is the root of an archivestatic FilegetMountSource(Closeable handle) Return the mount source File for a given mount handle.static StringGet the name.static StringgetPathsString(Collection<VirtualFile> paths) Get the paths string for a collection of virtual filesstatic URIgetPhysicalURI(VirtualFile file) Get a physical URI for a virtual file.static URLgetPhysicalURL(VirtualFile file) Get a physical URL for a virtual file.static URIgetRootURI(VirtualFile file) Get the physical root URL of the filesystem of a virtual file.static URLgetRootURL(VirtualFile file) Get the physical root URL of the filesystem of a virtual file.static URIgetVirtualURI(VirtualFile file) Get the virtual URI for a virtual file.static URLgetVirtualURL(VirtualFile file) Get the virtual URL for a virtual file.static booleanstatic ManifestreadManifest(VirtualFile manifest) Read the manifest from given manifest VirtualFile.static voidrecursiveCopy(File original, File destDir) Recursively copy a file or directory from one location to another.static voidrecursiveCopy(File original, VirtualFile destDir) Recursively copy a file or directory from one location to another.static voidrecursiveCopy(VirtualFile original, File destDir) Recursively copy a file or directory from one location to another.static voidrecursiveCopy(VirtualFile original, VirtualFile destDir) Recursively copy a file or directory from one location to another.static booleanrecursiveDelete(File root) Attempt to recursively delete a real file.static booleanrecursiveDelete(VirtualFile root) Attempt to recursively delete a virtual file.static voidSafely close some resource without throwing an exception.static voidSafely close some resource without throwing an exception.static voidSafely close some resources without throwing an exception.static voidSafely close some resource without throwing an exception.static URLsanitizeURL(URL url) Ensure the url is convertible to URI by encoding spaces and percent characters if necessarystatic URIDeal with urls that may include spaces.static voidExpand a zip file to a destination directory.static voidwriteFile(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 voidwriteFile(VirtualFile virtualFile, InputStream is) Write the content from the givenInputStreamto the given virtual file, replacing its current contents (if any) or creating a new file if one does not exist.
-
Field Details
-
DEFAULT_ENCODING
-
VFS_PROTOCOL
-
FORCE_CASE_SENSITIVE_KEY
Constant representing the system property for forcing case sensitive- See Also:
-
VFS_URL_HANDLER
TheURLStreamHandlerfor the 'vfs' protocol -
FILE_URL_HANDLER
TheURLStreamHandlerfor the 'file' protocol -
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEThe default buffer size to use for copies- See Also:
-
forceCaseSensitive
private static boolean forceCaseSensitiveThis variable indicates if the FileSystem should force case sensitive independently if the underlying file system is case sensitive or not -
EMPTY_STREAM
-
GLOB_PATTERN
-
-
Constructor Details
-
VFSUtils
private VFSUtils()
-
-
Method Details
-
getPathsString
Get the paths string for a collection of virtual files- Parameters:
paths- the paths- Returns:
- the string
- Throws:
IllegalArgumentException- for null paths
-
addManifestLocations
public static void addManifestLocations(VirtualFile file, List<VirtualFile> paths) throws IOException Add manifest paths- Parameters:
file- the filepaths- the paths to add to- Throws:
IOException- if there is an error reading the manifest or the virtual file is closedIllegalStateException- if the file has no parentIllegalArgumentException- for a null file or paths
-
getManifest
Get a manifest from a virtual file, assuming the virtual file is the root of an archive- Parameters:
archive- the root the archive- Returns:
- the manifest or null if not found
- Throws:
IOException- if there is an error reading the manifest or the virtual file is closedIllegalArgumentException- for a null archive
-
readManifest
Read the manifest from given manifest VirtualFile.- Parameters:
manifest- the VF to read from- Returns:
- JAR's manifest
- Throws:
IOException- if problems while opening VF stream occur
-
fixName
Fix a name (removes any trailing slash)- Parameters:
name- the name to fix- Returns:
- the fixed name
- Throws:
IllegalArgumentException- for a null name
-
decode
-
decode
-
getName
-
toURI
Deal with urls that may include spaces.- Parameters:
url- the url- Returns:
- uri the uri
- Throws:
URISyntaxException- for any error
-
sanitizeURL
Ensure the url is convertible to URI by encoding spaces and percent characters if necessary- Parameters:
url- to be sanitized- Returns:
- sanitized URL
- Throws:
URISyntaxException- if URI conversion can't be fixedMalformedURLException- if an error occurs
-
copyChildrenRecursive
public static void copyChildrenRecursive(VirtualFile original, VirtualFile target) throws IOException Copy all the children from the originalVirtualFilethe target recursively.- Parameters:
original- the file to copy children fromtarget- the file to copy the children to- Throws:
IOException- if any problems occur copying the files
-
copyStreamAndClose
Copy input stream to output stream and close them both- Parameters:
is- input streamos- output stream- Throws:
IOException- for any error
-
copyStreamAndClose
public static void copyStreamAndClose(InputStream is, OutputStream os, int bufferSize) throws IOException Copy input stream to output stream and close them both- Parameters:
is- input streamos- output streambufferSize- the buffer size to use- Throws:
IOException- for any error
-
copyStream
Copy input stream to output stream without closing streams. Flushes output stream when done.- Parameters:
is- input streamos- output stream- Throws:
IOException- for any error
-
copyStream
Copy input stream to output stream without closing streams. Flushes output stream when done.- Parameters:
is- input streamos- output streambufferSize- the buffer size to use- Throws:
IOException- for any error
-
writeFile
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.- Parameters:
virtualFile- the virtual file to writebytes- the bytes- Throws:
IOException- if an error occurs
-
writeFile
Write the content from the givenInputStreamto the given virtual file, replacing its current contents (if any) or creating a new file if one does not exist.- Parameters:
virtualFile- the virtual file to writeis- the input stream- Throws:
IOException- if an error occurs
-
getVirtualURL
Get the virtual URL for a virtual file. This URL can be used to access the virtual file; however, taking the file part of the URL and attempting to use it with theFileclass 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.- Parameters:
file- the virtual file- Returns:
- the URL
- Throws:
MalformedURLException- if the file cannot be coerced into a URL for some reason- See Also:
-
getVirtualURI
Get the virtual URI for a virtual file. Note: if the given VirtualFile refers to a directory at the time of this method invocation, a trailing slash will be appended to the URI; this means that invoking this method may require a filesystem access, and in addition, may not produce consistent results over time.- Parameters:
file- the virtual file- Returns:
- the URI
- Throws:
URISyntaxException- if the file cannot be coerced into a URI for some reason- See Also:
-
getPhysicalURL
Get a physical URL for a virtual file. See the warnings on theVirtualFile.getPhysicalFile()method before using this method.- Parameters:
file- the virtual file- Returns:
- the physical file URL
- Throws:
IOException- if an I/O error occurs getting the physical file
-
getPhysicalURI
Get a physical URI for a virtual file. See the warnings on theVirtualFile.getPhysicalFile()method before using this method.- Parameters:
file- the virtual file- Returns:
- the physical file URL
- Throws:
IOException- if an I/O error occurs getting the physical file
-
getRootURL
Get the physical root URL of the filesystem of a virtual file. This URL is suitable for use as a class loader's code source or in similar situations where only standard URL types (jarandfile) are supported.- Parameters:
file- the virtual file- Returns:
- the root URL
- Throws:
MalformedURLException- if the URL is not valid
-
getRootURI
Get the physical root URL of the filesystem of a virtual file. This URI is suitable for conversion to a class loader's code source URL or in similar situations where only standard URL types (jarandfile) are supported.- Parameters:
file- the virtual file- Returns:
- the root URI
- Throws:
URISyntaxException- if the URI is not valid
-
safeClose
Safely close some resource without throwing an exception. Any exception will be logged at TRACE level.- Parameters:
c- the resource
-
safeClose
Safely close some resource without throwing an exception. Any exception will be logged at TRACE level.- Parameters:
closeables- the resources
-
safeClose
-
safeClose
Safely close some resource without throwing an exception. Any exception will be logged at TRACE level.- Parameters:
zipFile- the resource
-
isForceCaseSensitive
public static boolean isForceCaseSensitive() -
exists
In case the file system is not case sensitive we compare the canonical path with the absolute path of the file after normalized.- Parameters:
file-- Returns:
-
recursiveDelete
Attempt to recursively delete a real file.- Parameters:
root- the real file to delete- Returns:
trueif the file was deleted
-
recursiveDelete
Attempt to recursively delete a virtual file.- Parameters:
root- the virtual file to delete- Returns:
trueif the file was deleted
-
recursiveCopy
Recursively copy a file or directory from one location to another.- Parameters:
original- the original file or directorydestDir- the destination directory- Throws:
IOException- if an I/O error occurs before the copy is complete
-
recursiveCopy
Recursively copy a file or directory from one location to another.- Parameters:
original- the original file or directorydestDir- the destination directory- Throws:
IOException- if an I/O error occurs before the copy is complete
-
recursiveCopy
Recursively copy a file or directory from one location to another.- Parameters:
original- the original virtual file or directorydestDir- the destination directory- Throws:
IOException- if an I/O error occurs before the copy is complete
-
recursiveCopy
Recursively copy a file or directory from one location to another.- Parameters:
original- the original virtual file or directorydestDir- the destination virtual directory- Throws:
IOException- if an I/O error occurs before the copy is complete
-
emptyStream
Get the empty input stream. This stream always reports an immediate EOF.- Returns:
- the empty input stream
-
createJarFileInputStream
Get an input stream that will always be consumable as a Zip/Jar file. The input stream will not be an instance of a JarInputStream, but will stream bytes according to the Zip specification. Using this method, a VFS file or directory can be written to disk as a normal jar/zip file.- Parameters:
virtualFile- The virtual to get a jar file input stream for- Returns:
- An input stream returning bytes according to the zip spec
- Throws:
IOException- if any problems occur
-
unzip
Expand a zip file to a destination directory. The directory must exist. If an error occurs, the destination directory may contain a partially-extracted archive, so cleanup is up to the caller.- Parameters:
zipFile- the zip filedestDir- the destination directory- Throws:
IOException- if an error occurs
-
getMountSource
-
getGlobPattern
Get a regular expression pattern which matches any path names which match the given glob. The glob patterns function similarly toantfile 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 Manual- Parameters:
glob- the glob to match- Returns:
- the pattern
-
canonicalize
-