|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.util.CmsFileUtil
public final class CmsFileUtil
Provides File utility functions.
Method Summary | |
---|---|
static java.lang.String |
addTrailingSeparator(java.lang.String path)
Adds a trailing separator to a path if required. |
static void |
checkResources(CmsObject cms,
java.util.List resources)
Checks if all resources are present. |
static void |
copy(java.lang.String fromFile,
java.lang.String toFile)
Simply version of a 1:1 binary file copy. |
static java.lang.String |
formatFilesize(long filesize,
java.util.Locale locale)
Returns the formatted filesize to Bytes, KB, MB or GB depending on the given value. |
static java.lang.String |
formatResourceNames(CmsRequestContext context,
java.util.List resources)
Returns a comma separated list of resource paths names, with the site root from the given OpenCms user context removed. |
static java.lang.String |
getExtension(java.lang.String resourceName)
Returns the extension of the given resource name, that is the part behind the last '.' char, converted to lower case letters. |
static java.lang.String |
getFileExtension(java.lang.String filename)
Deprecated. use getExtension(String) instead, it is better implemented |
static java.util.List |
getFiles(java.lang.String name,
java.io.FileFilter filter,
boolean includeSubtree)
Returns a list of all filtered files in the RFS. |
static java.lang.String |
getRepositoryName(java.lang.String repository,
java.lang.String vfspath,
boolean online)
Returns the file name for a given VFS name that has to be written to a repository in the "real" file system, by appending the VFS root path to the given base repository path, also adding an folder for the "online" or "offline" project. |
static java.lang.String |
getRfsPath(java.lang.String filename,
java.lang.String extension,
java.lang.String parameters)
Creates unique, valid RFS name for the given filename that contains a coded version of the given parameters, with the given file extension appended. |
static java.lang.String |
normalizePath(java.lang.String path)
Normalizes a file path that might contain '.. |
static java.lang.String |
normalizePath(java.lang.String path,
char separatorChar)
Normalizes a file path that might contain '.. |
static java.lang.String |
normalizePath(java.net.URL url)
Returns the normalized file path created from the given URL. |
static java.lang.String |
normalizePath(java.net.URL url,
char separatorChar)
Returns the normalized file path created from the given URL. |
static void |
purgeDirectory(java.io.File directory)
Deletes a directory in the file system and all subfolders of that directory. |
static byte[] |
readFile(java.io.File file)
Reads a file from the RFS and returns the file content. |
static byte[] |
readFile(java.lang.String filename)
Reads a file with the given name from the class loader and returns the file content. |
static java.lang.String |
readFile(java.lang.String filename,
java.lang.String encoding)
Reads a file from the class loader and converts it to a String with the specified encoding. |
static byte[] |
readFully(java.io.InputStream in)
Reads all bytes from the given input stream, closes it and returns the result in an array. |
static byte[] |
readFully(java.io.InputStream in,
boolean closeInputStream)
Reads all bytes from the given input stream, conditionally closes the given input stream and returns the result in an array. |
static byte[] |
readFully(java.io.InputStream in,
int size)
Reads the specified number of bytes from the given input stream and returns the result in an array. |
static byte[] |
readFully(java.io.InputStream in,
int size,
boolean closeStream)
Reads the specified number of bytes from the given input stream, conditionally closes the stream and returns the result in an array. |
static java.util.List |
removeRedundancies(java.util.List resourcenames)
Removes all resource names in the given List that are "redundant" because the parent folder name is also contained in the List. |
static java.util.List |
removeRedundantResources(java.util.List resources)
Removes all resources in the given List that are "redundant" because the parent folder is also contained in the List. |
static java.lang.String |
removeTrailingSeparator(java.lang.String path)
Removes a trailing separator from a path if required. |
static java.lang.String |
searchWebInfFolder(java.lang.String startFolder)
Searches for the OpenCms web application 'WEB-INF' folder during system startup, code or null if the 'WEB-INF' folder can not be found. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.lang.String addTrailingSeparator(java.lang.String path)
path
- the path to add the trailing separator to
public static void checkResources(CmsObject cms, java.util.List resources) throws CmsIllegalArgumentException
cms
- an initialized OpenCms user context which must have read access to all resourcesresources
- a list of vfs resource names to check
CmsIllegalArgumentException
- in case not all resources exist or can be read with the given OpenCms user contextpublic static void copy(java.lang.String fromFile, java.lang.String toFile) throws java.io.IOException
fromFile
- the name of the file to copytoFile
- the name of the target file
java.io.IOException
- if any IO error occurs during the copy operationpublic static java.lang.String formatFilesize(long filesize, java.util.Locale locale)
filesize
- in byteslocale
- the locale of the current OpenCms user or the System's default locale if the first choice
is not at hand.
public static java.lang.String formatResourceNames(CmsRequestContext context, java.util.List resources)
context
- the current users OpenCms context (optional, may be null
)resources
- a List of CmsResource
instances to get the names from
public static java.lang.String getExtension(java.lang.String resourceName)
The extension of a file is the part of the name after the last dot, including the dot. The extension of a folder is empty. All extensions are returned as lower case
Please note: No check is performed to ensure the given file name is not null
.
Examples:
/folder.test/
has an empty extension.
/folder.test/config
has an empty extension.
/strange.filename.
has an empty extension.
/document.PDF
has the extension .pdf
.
resourceName
- the resource to get the extension for
public static java.lang.String getFileExtension(java.lang.String filename)
getExtension(String)
instead, it is better implemented
The result does contain the '.' char. For example, if the input is "opencms.html"
,
then the result will be ".html"
.
If the given file name does not contain a '.' char, the empty String ""
is returned.
Please note: No check is performed to ensure the given file name is not null
.
filename
- the file name to get the extension for
public static java.util.List getFiles(java.lang.String name, java.io.FileFilter filter, boolean includeSubtree)
If the name
is not a folder the folder that contains the
given file will be used instead.
Despite the filter may not accept folders, every subfolder is traversed
if the includeSubtree
parameter is set.
name
- a folder or file namefilter
- a filterincludeSubtree
- if to include subfolders
File
objectspublic static java.lang.String getRepositoryName(java.lang.String repository, java.lang.String vfspath, boolean online)
repository
- the base repository pathvfspath
- the VFS root path to write to useonline
- flag indicates if the result should be used for the online project (true
) or not
public static java.lang.String getRfsPath(java.lang.String filename, java.lang.String extension, java.lang.String parameters)
This is used to create file names for the static export, or in a vfs disk cache.
filename
- the base file nameextension
- the extension to useparameters
- the parameters to code in the result file name
CmsStaticExportManager
public static java.lang.String normalizePath(java.lang.String path)
'../'
or './'
or '//'
elements to a normal absolute path, the path separator char used is File.separatorChar
.
path
- the path to normalize
normalizePath(String, char)
public static java.lang.String normalizePath(java.lang.String path, char separatorChar)
'../'
or './'
or '//'
elements to a normal absolute path.
Can also handle Windows like path information containing a drive letter,
like C:\path\..\
.
path
- the path to normalizeseparatorChar
- the file separator char to use, for example File.separatorChar
public static java.lang.String normalizePath(java.net.URL url)
The path part URL.getPath()
is used, unescaped and
normalized using normalizePath(String, char)
using File.separatorChar
.
url
- the URL to extract the path information from
File.separatorChar
normalizePath(URL, char)
public static java.lang.String normalizePath(java.net.URL url, char separatorChar)
The path part URL.getPath()
is used, unescaped and
normalized using normalizePath(String, char)
.
url
- the URL to extract the path information fromseparatorChar
- the file separator char to use, for example File.separatorChar
public static void purgeDirectory(java.io.File directory)
directory
- the directory to deletepublic static byte[] readFile(java.io.File file) throws java.io.IOException
file
- the file to read
java.io.IOException
- in case of file access errorspublic static byte[] readFile(java.lang.String filename) throws java.io.IOException
filename
- the file to read
java.io.IOException
- in case of file access errorspublic static java.lang.String readFile(java.lang.String filename, java.lang.String encoding) throws java.io.IOException
filename
- the file to readencoding
- the encoding to use when converting the file content to a String
java.io.IOException
- in case of file access errorspublic static byte[] readFully(java.io.InputStream in) throws java.io.IOException
in
- the input stream to read the bytes from
java.io.IOException
- in case of errors in the underlying java.io methods usedpublic static byte[] readFully(java.io.InputStream in, boolean closeInputStream) throws java.io.IOException
in
- the input stream to read the bytes fromcloseInputStream
- if true the given stream will be closed afterwards
java.io.IOException
- in case of errors in the underlying java.io methods usedpublic static byte[] readFully(java.io.InputStream in, int size) throws java.io.IOException
in
- the input stream to read the bytes fromsize
- the number of bytes to read
java.io.IOException
- in case of errors in the underlying java.io methods usedpublic static byte[] readFully(java.io.InputStream in, int size, boolean closeStream) throws java.io.IOException
in
- the input stream to read the bytes fromsize
- the number of bytes to readcloseStream
- if true the given stream will be closed
java.io.IOException
- in case of errors in the underlying java.io methods usedpublic static java.util.List removeRedundancies(java.util.List resourcenames)
The content of the input list is not modified.
resourcenames
- a list of VFS pathnames to check for redundencies (Strings)
removeRedundantResources(List)
public static java.util.List removeRedundantResources(java.util.List resources)
The content of the input list is not modified.
resources
- a list of CmsResource
objects to check for redundencies
removeRedundancies(List)
public static java.lang.String removeTrailingSeparator(java.lang.String path)
In case we have the root folder "/", the separator is not removed.
path
- the path to remove the trailing separator from
public static java.lang.String searchWebInfFolder(java.lang.String startFolder)
null
if the 'WEB-INF' folder can not be found.
startFolder
- the folder where to start searching
null
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |