org.jboss.virtual
Class VFSUtils

java.lang.Object
  extended by org.jboss.virtual.VFSUtils

public class VFSUtils
extends Object

VFS Utilities

Version:
$Revision: 1.1 $
Author:
Adrian Brock, Ales Justin

Field Summary
static String CASE_SENSITIVE_QUERY
           
static String FILE_PROTOCOL
          Constant representing the URL file protocol
static String FORCE_CASE_SENSITIVE_KEY
          Key used to force case sensitive path checking in vfsfile
static String FORCE_COPY_KEY
          The system no force copy key / query
static String FORCE_NO_REAPER_KEY
          Key used to turn off reaper mode in vfszip - forcing synchronous (slower) handling of files
static String FORCE_VFS_JAR_KEY
          Key used to force fallback from vfszip (default) to vfsjar
static String IS_TEMP_FILE
          The temp marker flag
static String JAR_URL_SEPARATOR
          Standard separator for JAR URL
static String NO_REAPER_QUERY
           
static String OPTIMIZE_FOR_MEMORY_KEY
          Key used to turn on memory optimizations - less cache use at the expense of performance
static String USE_COPY_QUERY
           
static String VFS_CACHE_KEY
          Key used to determine VFS Cache impl
static String VFS_LINK_INFIX
          The link
static String VFS_LINK_NAME
          The link name
static String VFS_LINK_PROPERTIES_SUFFIX
          The link properties
static String VFS_LINK_TARGET
          The link target
 
Constructor Summary
VFSUtils()
           
 
Method Summary
static void addManifestLocations(VirtualFile file, List<VirtualFile> paths)
          Add manifest paths
protected static VirtualFile copy(VirtualFile file, CopyMechanism mechanism)
          Create temp.
static void copyStream(InputStream is, OutputStream os)
          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 String decode(String path)
          Decode the path with UTF-8 encoding..
static String decode(String path, String encoding)
          Decode the path.
static void disableCaseSensitive(VFS vfs)
          Disable case sensitive for vfs param.
static void disableCaseSensitive(VirtualFile file)
          Disable case sensitive for file param.
static void disableCopy(VFS vfs)
          Disable copy for vfs param.
static void disableCopy(VirtualFile file)
          Disable copy for file param.
static void disableNoReaper(VFS vfs)
          Disable reaper for vfs param.
static void disableNoReaper(VirtualFile file)
          Disable reaper for file param.
protected static void disableOption(VFS vfs, String optionName)
          Disable option.
protected static void disableOption(VirtualFile file, String optionName)
          Disable option.
static void enableCaseSensitive(VFS vfs)
          Enable case sensitive for vfs param.
static void enableCaseSensitive(VirtualFile file)
          Enable case sensitive for file param.
static void enableCopy(VFS vfs)
          Enable copy for vfs param.
static void enableCopy(VirtualFile file)
          Enable copy for file param.
static void enableNoReaper(VFS vfs)
          Enable reaper for vfs param.
static void enableNoReaper(VirtualFile file)
          Enable reaper for file param.
protected static void enableOption(VFS vfs, String optionName)
          Enable option.
protected static void enableOption(VirtualFile file, String optionName)
          Enable option.
static VirtualFile explode(VirtualFile file)
          Force explode.
static String fixName(String name)
          Fix a name (removes any trailing slash)
static URI getCompatibleURI(VirtualFile file)
          Get spec compatilbe uri from virtual file.
static URL getCompatibleURL(VirtualFile file)
          Get spec compatilbe url from virtual file.
static String getKey(VFSContext context)
          Get path key.
static Manifest getManifest(VFS archive)
          Get a manifest from a virtual file system, assuming the root of the VFS is the root of an archive
static Manifest getManifest(VirtualFile archive)
          Get a manifest from a virtual file, assuming the virtual file is the root of an archive
static String getName(URI uri)
          Get the name.
static String getOption(VFS vfs, String key)
          Get the option.
static
<T> T
getOption(VFS vfs, String key, Class<T> exactType)
          Get the option.
static String getOption(VirtualFile file, String key)
          Get the option.
static
<T> T
getOption(VirtualFile file, String key, Class<T> exactType)
          Get the option.
static String getPathsString(Collection<VirtualFile> paths)
          Get the paths string for a collection of virtual files
static URL getRealURL(VirtualFile file)
          Get real url.
static String getRelativePath(VFSContext context, URI uri)
          Get relative path.
static boolean isLink(String name)
          Does a vf name contain the VFS link prefix
static boolean isNestedFile(VirtualFile file)
          Is file handle nested.
static boolean isTemporaryFile(VirtualFile file)
          Is the virtual file temporary.
static void parseLinkProperties(InputStream is, List<LinkInfo> info, Properties props)
          Parse a properties link file
static Map<String,String> parseURLQuery(String query)
          Take a URL.getQuery string and parse it into name=value pairs
static List<LinkInfo> readLinkInfo(InputStream is, String name, Properties props)
          Read the link information from the stream based on the type as determined from the name suffix.
static Manifest readManifest(VirtualFile manifest)
          Read the manifest from given manifest VirtualFile.
static URL sanitizeURL(URL url)
          Ensure the url is convertible to URI by encoding spaces and percent characters if necessary
static void stopCache()
          Stop cache.
static String stripProtocol(URI uri)
          Strip protocol from url string.
static VirtualFile temp(VirtualFile file)
          Create temp.
static URI toURI(URL url)
          Deal with urls that may include spaces.
static VirtualFile unjar(VirtualFile file)
          Unjar.
static VirtualFile unpack(VirtualFile file)
          Unpack the nested artifact under file param.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VFS_LINK_INFIX

public static final String VFS_LINK_INFIX
The link

See Also:
Constant Field Values

VFS_LINK_PROPERTIES_SUFFIX

public static final String VFS_LINK_PROPERTIES_SUFFIX
The link properties

See Also:
Constant Field Values

VFS_LINK_NAME

public static final String VFS_LINK_NAME
The link name

See Also:
Constant Field Values

VFS_LINK_TARGET

public static final String VFS_LINK_TARGET
The link target

See Also:
Constant Field Values

FORCE_COPY_KEY

public static final String FORCE_COPY_KEY
The system no force copy key / query

See Also:
Constant Field Values

USE_COPY_QUERY

public static final String USE_COPY_QUERY
See Also:
Constant Field Values

FORCE_VFS_JAR_KEY

public static final String FORCE_VFS_JAR_KEY
Key used to force fallback from vfszip (default) to vfsjar

See Also:
Constant Field Values

FORCE_NO_REAPER_KEY

public static final String FORCE_NO_REAPER_KEY
Key used to turn off reaper mode in vfszip - forcing synchronous (slower) handling of files

See Also:
Constant Field Values

NO_REAPER_QUERY

public static final String NO_REAPER_QUERY
See Also:
Constant Field Values

FORCE_CASE_SENSITIVE_KEY

public static final String FORCE_CASE_SENSITIVE_KEY
Key used to force case sensitive path checking in vfsfile

See Also:
Constant Field Values

CASE_SENSITIVE_QUERY

public static final String CASE_SENSITIVE_QUERY
See Also:
Constant Field Values

OPTIMIZE_FOR_MEMORY_KEY

public static final String OPTIMIZE_FOR_MEMORY_KEY
Key used to turn on memory optimizations - less cache use at the expense of performance

See Also:
Constant Field Values

VFS_CACHE_KEY

public static final String VFS_CACHE_KEY
Key used to determine VFS Cache impl

See Also:
Constant Field Values

FILE_PROTOCOL

public static final String FILE_PROTOCOL
Constant representing the URL file protocol

See Also:
Constant Field Values

JAR_URL_SEPARATOR

public static final String JAR_URL_SEPARATOR
Standard separator for JAR URL

See Also:
Constant Field Values

IS_TEMP_FILE

public static final String IS_TEMP_FILE
The temp marker flag

See Also:
Constant Field Values
Constructor Detail

VFSUtils

public VFSUtils()
Method Detail

stopCache

public static void stopCache()
Stop cache.


getPathsString

public static String getPathsString(Collection<VirtualFile> paths)
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 file
paths - the paths to add to
Throws:
IOException - if there is an error reading the manifest or the virtual file is closed
IllegalStateException - if the file has no parent
IllegalArgumentException - for a null file or paths

getManifest

public static Manifest getManifest(VirtualFile archive)
                            throws IOException
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 closed
IllegalArgumentException - for a null archive

readManifest

public static Manifest readManifest(VirtualFile manifest)
                             throws IOException
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

getManifest

public static Manifest getManifest(VFS archive)
                            throws IOException
Get a manifest from a virtual file system, assuming the root of the VFS is the root of an archive

Parameters:
archive - the vfs
Returns:
the manifest or null if not found
Throws:
IOException - if there is an error reading the manifest
IllegalArgumentException - for a null archive

fixName

public static String fixName(String name)
Fix a name (removes any trailing slash)

Parameters:
name - the name to fix
Returns:
the fixed name
Throws:
IllegalArgumentException - for a null name

decode

public static String decode(String path)
Decode the path with UTF-8 encoding..

Parameters:
path - the path to decode
Returns:
decoded path

decode

public static String decode(String path,
                            String encoding)
Decode the path.

Parameters:
path - the path to decode
encoding - the encodeing
Returns:
decoded path

getName

public static String getName(URI uri)
Get the name.

Parameters:
uri - the uri
Returns:
name from uri's path

parseURLQuery

public static Map<String,String> parseURLQuery(String query)
Take a URL.getQuery string and parse it into name=value pairs

Parameters:
query - Possibly empty/null url query string
Returns:
String[] for the name/value pairs in the query. May be empty but never null.

isLink

public static boolean isLink(String name)
Does a vf name contain the VFS link prefix

Parameters:
name - - the name portion of a virtual file
Returns:
true if the name starts with VFS_LINK_PREFIX, false otherwise

readLinkInfo

public static List<LinkInfo> readLinkInfo(InputStream is,
                                          String name,
                                          Properties props)
                                   throws IOException,
                                          URISyntaxException
Read the link information from the stream based on the type as determined from the name suffix.

Parameters:
is - - input stream to the link file contents
name - - the name of the virtual file representing the link
props - the propertes
Returns:
a list of the links read from the stream
Throws:
IOException - on failure to read/parse the stream
URISyntaxException - for an error parsing a URI

parseLinkProperties

public static void parseLinkProperties(InputStream is,
                                       List<LinkInfo> info,
                                       Properties props)
                                throws IOException,
                                       URISyntaxException
Parse a properties link file

Parameters:
is - - input stream to the link file contents
info - the link infos
props - the propertes
Throws:
IOException - on failure to read/parse the stream
URISyntaxException - for an error parsing a URI

toURI

public static URI toURI(URL url)
                 throws URISyntaxException
Deal with urls that may include spaces.

Parameters:
url - the url
Returns:
uri the uri
Throws:
URISyntaxException - for any error

sanitizeURL

public static URL sanitizeURL(URL url)
                       throws URISyntaxException,
                              MalformedURLException
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 fixed
MalformedURLException - if an error occurs

getOption

public static String getOption(VirtualFile file,
                               String key)
Get the option.

Parameters:
file - the file
key - the option key
Returns:
key's option

getOption

public static String getOption(VFS vfs,
                               String key)
Get the option.

Parameters:
vfs - the vfs
key - the option key
Returns:
key's option

getOption

public static <T> T getOption(VirtualFile file,
                              String key,
                              Class<T> exactType)
Get the option.

Type Parameters:
T - exact type
Parameters:
file - the file
key - the option key
exactType - the exact type
Returns:
key's option

getOption

public static <T> T getOption(VFS vfs,
                              String key,
                              Class<T> exactType)
Get the option.

Type Parameters:
T - exact type
Parameters:
vfs - the vfs
key - the option key
exactType - the exact type
Returns:
key's option

enableOption

protected static void enableOption(VirtualFile file,
                                   String optionName)
Enable option.

Parameters:
file - the file
optionName - option name

disableOption

protected static void disableOption(VirtualFile file,
                                    String optionName)
Disable option.

Parameters:
file - the file
optionName - option name

enableOption

protected static void enableOption(VFS vfs,
                                   String optionName)
Enable option.

Parameters:
vfs - the vfs
optionName - option name

disableOption

protected static void disableOption(VFS vfs,
                                    String optionName)
Disable option.

Parameters:
vfs - the vfs
optionName - option name

enableCopy

public static void enableCopy(VirtualFile file)
Enable copy for file param.

Parameters:
file - the file

disableCopy

public static void disableCopy(VirtualFile file)
Disable copy for file param.

Parameters:
file - the file

enableCopy

public static void enableCopy(VFS vfs)
Enable copy for vfs param.

Parameters:
vfs - the vfs

disableCopy

public static void disableCopy(VFS vfs)
Disable copy for vfs param.

Parameters:
vfs - the vfs

enableNoReaper

public static void enableNoReaper(VirtualFile file)
Enable reaper for file param.

Parameters:
file - the file

disableNoReaper

public static void disableNoReaper(VirtualFile file)
Disable reaper for file param.

Parameters:
file - the file

enableNoReaper

public static void enableNoReaper(VFS vfs)
Enable reaper for vfs param.

Parameters:
vfs - the vfs

disableNoReaper

public static void disableNoReaper(VFS vfs)
Disable reaper for vfs param.

Parameters:
vfs - the vfs

enableCaseSensitive

public static void enableCaseSensitive(VirtualFile file)
Enable case sensitive for file param.

Parameters:
file - the file

disableCaseSensitive

public static void disableCaseSensitive(VirtualFile file)
Disable case sensitive for file param.

Parameters:
file - the file

enableCaseSensitive

public static void enableCaseSensitive(VFS vfs)
Enable case sensitive for vfs param.

Parameters:
vfs - the vfs

disableCaseSensitive

public static void disableCaseSensitive(VFS vfs)
Disable case sensitive for vfs param.

Parameters:
vfs - the vfs

isTemporaryFile

public static boolean isTemporaryFile(VirtualFile file)
Is the virtual file temporary.

Parameters:
file - the file
Returns:
true if temporary, false otherwise

unpack

public static VirtualFile unpack(VirtualFile file)
                          throws IOException,
                                 URISyntaxException
Unpack the nested artifact under file param.

Parameters:
file - the file to unpack
Returns:
unpacked file
Throws:
IOException - for any io error
URISyntaxException - for any uri error

explode

public static VirtualFile explode(VirtualFile file)
                           throws IOException,
                                  URISyntaxException
Force explode. Explode archives or nested entries.

Parameters:
file - the file to explode
Returns:
exploded file
Throws:
IOException - for any io error
URISyntaxException - for any uri error

temp

public static VirtualFile temp(VirtualFile file)
                        throws IOException,
                               URISyntaxException
Create temp.

Parameters:
file - the file to temp
Returns:
temp file
Throws:
IOException - for any io error
URISyntaxException - for any uri error

unjar

public static VirtualFile unjar(VirtualFile file)
                         throws IOException,
                                URISyntaxException
Unjar.

Parameters:
file - the file to unjar
Returns:
temp file
Throws:
IOException - for any io error
URISyntaxException - for any uri error

copy

protected static VirtualFile copy(VirtualFile file,
                                  CopyMechanism mechanism)
                           throws IOException,
                                  URISyntaxException
Create temp.

Parameters:
file - the file to unpack/explode
mechanism - the copy mechanism
Returns:
temp file
Throws:
IOException - for any io error
URISyntaxException - for any uri error

isNestedFile

public static boolean isNestedFile(VirtualFile file)
                            throws IOException
Is file handle nested.

Parameters:
file - the file handle to check
Returns:
true if file/dir is nested otherwise false
Throws:
IOException - for any error

copyStreamAndClose

public static void copyStreamAndClose(InputStream is,
                                      OutputStream os)
                               throws IOException
Copy input stream to output stream and close them both

Parameters:
is - input stream
os - output stream
Throws:
IOException - for any error

copyStream

public static void copyStream(InputStream is,
                              OutputStream os)
                       throws IOException
Copy input stream to output stream without closing streams. Flushes output stream when done.

Parameters:
is - input stream
os - output stream
Throws:
IOException - for any error

getCompatibleURL

public static URL getCompatibleURL(VirtualFile file)
                            throws Exception
Get spec compatilbe url from virtual file.

Parameters:
file - the virtual file
Returns:
spec compatible url
Throws:
Exception - for any error

getCompatibleURI

public static URI getCompatibleURI(VirtualFile file)
                            throws Exception
Get spec compatilbe uri from virtual file.

Parameters:
file - the virtual file
Returns:
spec compatible uri
Throws:
Exception - for any error

getRealURL

public static URL getRealURL(VirtualFile file)
                      throws IOException,
                             URISyntaxException
Get real url. The closest thing that doesn't need the vfs url handlers.

Parameters:
file - the virtual file
Returns:
real url
Throws:
IOException - for any error
URISyntaxException - for any uri syntac error

getRelativePath

public static String getRelativePath(VFSContext context,
                                     URI uri)
Get relative path.

Parameters:
context - the vfs context
uri - the uri
Returns:
uri's relative path to context's root

stripProtocol

public static String stripProtocol(URI uri)
Strip protocol from url string.

Parameters:
uri - the uri
Returns:
uri's path string

getKey

public static String getKey(VFSContext context)
Get path key.

Parameters:
context - the vfs context
Returns:
contex's root path w/o protocol


Copyright © 2011 JBoss, A division of Red Hat, Inc. All Rights Reserved.