public class VFSUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_SIZE
The default buffer size to use for copies
|
static String |
VFS_PROTOCOL
Constant representing the URL vfs protocol
|
Modifier and Type | Method and Description |
---|---|
static void |
addManifestLocations(VirtualFile file,
List<VirtualFile> paths)
Add manifest paths
|
static void |
copyChildrenRecursive(VirtualFile original,
VirtualFile target)
Copy all the children from the original
VirtualFile the target recursively. |
static void |
copyStream(InputStream is,
OutputStream os)
Copy input stream to output stream without closing streams.
|
static void |
copyStream(InputStream is,
OutputStream os,
int bufferSize)
Copy input stream to output stream without closing streams.
|
static void |
copyStreamAndClose(InputStream is,
OutputStream os)
Copy input stream to output stream and close them both
|
static void |
copyStreamAndClose(InputStream is,
OutputStream os,
int bufferSize)
Copy input stream to output stream and close them both
|
static InputStream |
createJarFileInputStream(VirtualFile virtualFile)
Get an input stream that will always be consumable as a Zip/Jar file.
|
static String |
decode(String path)
Decode the path with UTF-8 encoding..
|
static String |
decode(String path,
String encoding)
Decode the path.
|
static InputStream |
emptyStream()
Get the empty input stream.
|
static String |
fixName(String name)
Fix a name (removes any trailing slash)
|
static Pattern |
getGlobPattern(String glob)
Get a regular expression pattern which matches any path names which match the given glob.
|
static Manifest |
getManifest(VirtualFile archive)
Get a manifest from a virtual file, assuming the virtual file is the root of an archive
|
static File |
getMountSource(Closeable handle)
Return the mount source File for a given mount handle.
|
static String |
getName(URI uri)
Get the name.
|
static String |
getPathsString(Collection<VirtualFile> paths)
Get the paths string for a collection of virtual files
|
static URI |
getPhysicalURI(VirtualFile file)
Get a physical URI for a virtual file.
|
static URL |
getPhysicalURL(VirtualFile file)
Get a physical URL for a virtual file.
|
static URI |
getRootURI(VirtualFile file)
Get the physical root URL of the filesystem of a virtual file.
|
static URL |
getRootURL(VirtualFile file)
Get the physical root URL of the filesystem of a virtual file.
|
static URI |
getVirtualURI(VirtualFile file)
Get the virtual URI for a virtual file.
|
static URL |
getVirtualURL(VirtualFile file)
Get the virtual URL for a virtual file.
|
static Map<String,String> |
parseURLQuery(String query)
Take a URL.getQuery string and parse it into name=value pairs
|
static Manifest |
readManifest(VirtualFile manifest)
Read the manifest from given manifest VirtualFile.
|
static void |
recursiveCopy(File original,
File destDir)
Recursively copy a file or directory from one location to another.
|
static void |
recursiveCopy(File original,
VirtualFile destDir)
Recursively copy a file or directory from one location to another.
|
static void |
recursiveCopy(VirtualFile original,
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(File root)
Attempt to recursively delete a real file.
|
static boolean |
recursiveDelete(VirtualFile root)
Attempt to recursively delete a virtual file.
|
static void |
safeClose(Closeable... closeables)
Safely close some resource without throwing an exception.
|
static void |
safeClose(Closeable c)
Safely close some resource without throwing an exception.
|
static void |
safeClose(Iterable<? extends Closeable> ci)
Safely close some resources without throwing an exception.
|
static void |
safeClose(ZipFile zipFile)
Safely close some resource without throwing an exception.
|
static URL |
sanitizeURL(URL url)
Ensure the url is convertible to URI by encoding spaces and percent characters if necessary
|
static URI |
toURI(URL url)
Deal with urls that may include spaces.
|
static void |
unzip(File zipFile,
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,
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. |
public static final String VFS_PROTOCOL
public static final int DEFAULT_BUFFER_SIZE
public static String getPathsString(Collection<VirtualFile> paths)
paths
- the pathsIllegalArgumentException
- for null pathspublic static void addManifestLocations(VirtualFile file, List<VirtualFile> paths) throws IOException
file
- the filepaths
- the paths to add toIOException
- 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 pathspublic static Manifest getManifest(VirtualFile archive) throws IOException
archive
- the root the archiveIOException
- if there is an error reading the manifest or the virtual file is closedIllegalArgumentException
- for a null archivepublic static Manifest readManifest(VirtualFile manifest) throws IOException
manifest
- the VF to read fromIOException
- if problems while opening VF stream occurpublic static String fixName(String name)
name
- the name to fixIllegalArgumentException
- for a null namepublic static String decode(String path)
path
- the path to decodepublic static String decode(String path, String encoding)
path
- the path to decodeencoding
- the encodingpublic static String getName(URI uri)
uri
- the uripublic static Map<String,String> parseURLQuery(String query)
query
- Possibly empty/null url query stringpublic static URI toURI(URL url) throws URISyntaxException
url
- the urlURISyntaxException
- for any errorpublic static URL sanitizeURL(URL url) throws URISyntaxException, MalformedURLException
url
- to be sanitizedURISyntaxException
- if URI conversion can't be fixedMalformedURLException
- if an error occurspublic static void copyChildrenRecursive(VirtualFile original, VirtualFile target) throws IOException
VirtualFile
the target recursively.original
- the file to copy children fromtarget
- the file to copy the children toIOException
- if any problems occur copying the filespublic static void copyStreamAndClose(InputStream is, OutputStream os) throws IOException
is
- input streamos
- output streamIOException
- for any errorpublic static void copyStreamAndClose(InputStream is, OutputStream os, int bufferSize) throws IOException
is
- input streamos
- output streambufferSize
- the buffer size to useIOException
- for any errorpublic static void copyStream(InputStream is, OutputStream os) throws IOException
is
- input streamos
- output streamIOException
- for any errorpublic static void copyStream(InputStream is, OutputStream os, int bufferSize) throws IOException
is
- input streamos
- output streambufferSize
- the buffer size to useIOException
- for any errorpublic static void writeFile(VirtualFile virtualFile, byte[] bytes) throws IOException
virtualFile
- the virtual file to writebytes
- the bytesIOException
- if an error occurspublic static void writeFile(VirtualFile virtualFile, InputStream is) throws 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 streamIOException
- if an error occurspublic static URL getVirtualURL(VirtualFile file) throws 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 fileMalformedURLException
- if the file cannot be coerced into a URL for some reasonVirtualFile.asDirectoryURL()
,
VirtualFile.asFileURL()
public static URI getVirtualURI(VirtualFile file) throws URISyntaxException
file
- the virtual fileURISyntaxException
- if the file cannot be coerced into a URI for some reasonVirtualFile.asDirectoryURI()
,
VirtualFile.asFileURI()
public static URL getPhysicalURL(VirtualFile file) throws IOException
VirtualFile.getPhysicalFile()
method
before using this method.file
- the virtual fileIOException
- if an I/O error occurs getting the physical filepublic static URI getPhysicalURI(VirtualFile file) throws IOException
VirtualFile.getPhysicalFile()
method
before using this method.file
- the virtual fileIOException
- if an I/O error occurs getting the physical filepublic static URL getRootURL(VirtualFile file) throws MalformedURLException
jar
and file
) are supported.file
- the virtual fileMalformedURLException
- if the URL is not validpublic static URI getRootURI(VirtualFile file) throws URISyntaxException
jar
and file
) are supported.file
- the virtual fileURISyntaxException
- if the URI is not validpublic static void safeClose(Closeable c)
c
- the resourcepublic static void safeClose(Closeable... closeables)
closeables
- the resourcespublic static void safeClose(Iterable<? extends Closeable> ci)
ci
- the resourcespublic static void safeClose(ZipFile zipFile)
zipFile
- the resourcepublic static boolean recursiveDelete(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(File original, File destDir) throws IOException
original
- the original file or directorydestDir
- the destination directoryIOException
- if an I/O error occurs before the copy is completepublic static void recursiveCopy(File original, VirtualFile destDir) throws IOException
original
- the original file or directorydestDir
- the destination directoryIOException
- if an I/O error occurs before the copy is completepublic static void recursiveCopy(VirtualFile original, File destDir) throws IOException
original
- the original virtual file or directorydestDir
- the destination directoryIOException
- if an I/O error occurs before the copy is completepublic static void recursiveCopy(VirtualFile original, VirtualFile destDir) throws IOException
original
- the original virtual file or directorydestDir
- the destination virtual directoryIOException
- if an I/O error occurs before the copy is completepublic static InputStream emptyStream()
public static InputStream createJarFileInputStream(VirtualFile virtualFile) throws IOException
virtualFile
- The virtual to get a jar file input stream forIOException
- if any problems occurpublic static void unzip(File zipFile, File destDir) throws IOException
zipFile
- the zip filedestDir
- the destination directoryIOException
- if an error occurspublic static File getMountSource(Closeable handle)
handle
- The handle to get the source forpublic static Pattern getGlobPattern(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 matchCopyright © 2012 JBoss by Red Hat. All Rights Reserved.