railo.commons.io.res.util
Class ResourceUtil

java.lang.Object
  extended by railo.commons.io.res.util.ResourceUtil

public final class ResourceUtil
extends Object


Field Summary
static char FILE_ANTI_SEPERATOR
          Field FILE_ANTI_SEPERATOR
static char FILE_SEPERATOR
          Field FILE_SEPERATOR
static short LEVEL_FILE
          Field LEVEL_FILE
static short LEVEL_GRAND_PARENT_FILE
          Field LEVEL_GRAND_PARENT_FILE
static short LEVEL_PARENT_FILE
          Field LEVEL_PARENT_FILE
static int MIMETYPE_CHECK_EXTENSION
           
static int MIMETYPE_CHECK_HEADER
           
static short TYPE_DIR
          Field TYPE_DIR
static short TYPE_FILE
          Field TYPE_FILE
 
Constructor Summary
ResourceUtil()
           
 
Method Summary
static void _deleteContent(Resource src, ResourceFilter filter, boolean deleteDirectories)
           
static boolean canRW(Resource res)
          check if file is read and writable
static Resource changeExtension(Resource file, String newExtension)
          change extesnion of file and return new file
static void checkCopyToOK(Resource source, Resource target)
          check if copying a file is ok with the rules for the Resource interface, to not change this rules.
static void checkCreateDirectoryOK(Resource resource, boolean createParentWhenNotExists)
          check if directory creation is ok with the rules for the Resource interface, to not change this rules.
static void checkCreateFileOK(Resource resource, boolean createParentWhenNotExists)
          check if file creating is ok with the rules for the Resource interface, to not change this rules.
static void checkGetInputStreamOK(Resource resource)
          check if getting a inputstream of the file is ok with the rules for the Resource interface, to not change this rules.
static void checkGetOutputStreamOK(Resource resource)
          check if getting a outputstream of the file is ok with the rules for the Resource interface, to not change this rules.
static void checkMoveToOK(Resource source, Resource target)
          check if moveing a file is ok with the rules for the Resource interface, to not change this rules.
static void checkRemoveOK(Resource resource)
          check if removing the file is ok with the rules for the Resource interface, to not change this rules.
static void clear(Resource res)
           
static void copy(Resource src, Resource trg)
           
static void copyRecursive(Resource src, Resource trg)
          copy a file or directory recursive (with his content)
static void copyRecursive(Resource src, Resource trg, ResourceFilter filter)
          copy a file or directory recursive (with his content)
static void createDirectoryEL(Resource res, boolean force)
           
static void createFileEL(Resource res, boolean force)
           
static boolean createNewResourceEL(Resource res)
          creates a new File
static Resource createResource(Resource res, short level, short type)
          create a file if possible, return file if ok, otherwise return null
static void deleteContent(Resource src, ResourceFilter filter)
           
static void deleteEmptyFolders(Resource res)
           
static void deleteFileOlderThan(Resource res, long date, ExtensionResourceFilter filter)
           
static int directrySize(Resource dir, ResourceFilter filter)
           
static int directrySize(Resource dir, ResourceNameFilter filter)
           
static boolean exists(Resource res)
           
static String getCanonicalPathEL(Resource res)
          Returns the canonical form of this abstract pathname.
static Resource getCanonicalResourceEL(Resource res)
          Returns the canonical form of this abstract pathname.
static ContentType getContentType(Resource resource)
           
static String getExtension(Resource res, String defaultValue)
          get the Extension of a file
static String getExtension(String strFile, String defaultValue)
          get the Extension of a file
static String getMimeType(Resource res, int checkingType, String defaultValue)
           
static String getMimeType(Resource res, String defaultValue)
          return the mime type of a file, dont check extension
static String getName(String strFileName)
           
static String getPathToChild(Resource file, Resource dir)
          return diffrents of one file to a other if first is child of second otherwise return null
static long getRealSize(Resource res)
          return the size of the Resource, other than method length of Resource this mthod return the size of all files in a directory
static long getRealSize(Resource res, ResourceFilter filter)
          return the size of the Resource, other than method length of Resource this mthod return the size of all files in a directory
static Resource getResource(PageContext pc, PageSource ps)
          Deprecated. use instead PageSource.getResourceTranslated(PageContext)
static Resource getResource(PageContext pc, PageSource ps, Resource defaultValue)
           
static boolean isChildOf(Resource file, Resource dir)
          check if file is a child of given directory
static boolean isEmpty(Resource res)
          return if Resource is empty, means is directory and has no children or a empty file, if not exist return false.
static boolean isEmptyDirectory(Resource res)
           
static boolean isEmptyFile(Resource res)
           
static boolean isUNCPath(String path)
           
static Resource[] listResources(Resource[] resources, ResourceFilter filter)
          list childrn of all given resources
static Resource[] listResources(Resource res, ResourceFilter filter)
           
static Resource[] merge(Resource[] srcs, Resource[] trgs)
           
static String merge(String parent, String child)
          merge to path parts to one
static void moveTo(Resource src, Resource dest)
           
static String[] names(Resource[] resources)
           
static String prettifyPath(String path)
           
static void removeChildren(Resource res)
           
static void removeChildren(Resource res, ResourceFilter filter)
           
static void removeChildren(Resource res, ResourceNameFilter filter)
           
static void removeChildrenEL(Resource res)
           
static void removeChildrenEL(Resource res, ResourceFilter filter)
           
static void removeChildrenEL(Resource res, ResourceNameFilter filter)
           
static void removeEL(Resource res, boolean force)
           
static String removeScheme(String scheme, String path)
           
static void setAttribute(Resource res, String attributes)
           
static String[] splitFileName(String fileName)
          split a FileName in Parts
static Resource toExactResource(Resource res)
          transalte the path of the file to a existing file path by changing case of letters Works only on Linux, becasue Example Unix: we have a existing file with path "/usr/virtual/myFile.txt" now you call this method with path "/Usr/Virtual/myfile.txt" the result of the method will be "/usr/virtual/myFile.txt" if there are more file with rhe same name but different cases Example: /usr/virtual/myFile.txt /usr/virtual/myfile.txt /Usr/Virtual/myFile.txt the nearest case wil returned
static Resource toResource(File file)
           
static Resource toResourceExisting(Config config, String path)
           
static Resource toResourceExisting(PageContext pc, String path)
          cast a String (argumet destination) to a File Object, if destination is not a absolute, file object will be relative to current position (get from PageContext) file must exist otherwise throw exception
static Resource toResourceExisting(PageContext pc, String path, boolean allowRealpath)
           
static Resource toResourceExistingParent(PageContext pc, String destination)
          cast a String (argumet destination) to a File Object, if destination is not a absolute, file object will be relative to current position (get from PageContext) at least parent must exist
static Resource toResourceExistingParent(PageContext pc, String destination, boolean allowRealpath)
           
static Resource toResourceNotExisting(Config config, String path)
           
static Resource toResourceNotExisting(PageContext pc, String destination)
          cast a String (argument destination) to a File Object, if destination is not a absolute, file object will be relative to current position (get from PageContext) existing file is prefered but dont must exist
static Resource toResourceNotExisting(PageContext pc, String destination, boolean allowRealpath)
           
static void touch(Resource res)
          similat to linux bash fuction toch, create file if not exist oherwise change last modified date
static String translateAttribute(String attributes)
          sets attributes of a file on Windows system
static String translatePath(String path, boolean slashAdBegin, boolean slashAddEnd)
           
static String[] translatePathName(String path)
          transalte a path in a proper form and cut name away example susi\petere -> /susi/ and peter
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIMETYPE_CHECK_EXTENSION

public static final int MIMETYPE_CHECK_EXTENSION
See Also:
Constant Field Values

MIMETYPE_CHECK_HEADER

public static final int MIMETYPE_CHECK_HEADER
See Also:
Constant Field Values

FILE_SEPERATOR

public static final char FILE_SEPERATOR
Field FILE_SEPERATOR


FILE_ANTI_SEPERATOR

public static final char FILE_ANTI_SEPERATOR
Field FILE_ANTI_SEPERATOR


TYPE_DIR

public static final short TYPE_DIR
Field TYPE_DIR

See Also:
Constant Field Values

TYPE_FILE

public static final short TYPE_FILE
Field TYPE_FILE

See Also:
Constant Field Values

LEVEL_FILE

public static final short LEVEL_FILE
Field LEVEL_FILE

See Also:
Constant Field Values

LEVEL_PARENT_FILE

public static final short LEVEL_PARENT_FILE
Field LEVEL_PARENT_FILE

See Also:
Constant Field Values

LEVEL_GRAND_PARENT_FILE

public static final short LEVEL_GRAND_PARENT_FILE
Field LEVEL_GRAND_PARENT_FILE

See Also:
Constant Field Values
Constructor Detail

ResourceUtil

public ResourceUtil()
Method Detail

toResourceExisting

public static Resource toResourceExisting(PageContext pc,
                                          String path)
                                   throws ExpressionException
cast a String (argumet destination) to a File Object, if destination is not a absolute, file object will be relative to current position (get from PageContext) file must exist otherwise throw exception

Parameters:
pc - Page Context to et actuell position in filesystem
path - relative or absolute path for file object
Returns:
file object from destination
Throws:
ExpressionException

toResourceExisting

public static Resource toResourceExisting(PageContext pc,
                                          String path,
                                          boolean allowRealpath)
                                   throws ExpressionException
Throws:
ExpressionException

toResourceExisting

public static Resource toResourceExisting(Config config,
                                          String path)
                                   throws ExpressionException
Throws:
ExpressionException

toResourceNotExisting

public static Resource toResourceNotExisting(Config config,
                                             String path)

toResourceExistingParent

public static Resource toResourceExistingParent(PageContext pc,
                                                String destination)
                                         throws ExpressionException
cast a String (argumet destination) to a File Object, if destination is not a absolute, file object will be relative to current position (get from PageContext) at least parent must exist

Parameters:
pc - Page Context to et actuell position in filesystem
destination - relative or absolute path for file object
Returns:
file object from destination
Throws:
ExpressionException

toResourceExistingParent

public static Resource toResourceExistingParent(PageContext pc,
                                                String destination,
                                                boolean allowRealpath)
                                         throws ExpressionException
Throws:
ExpressionException

toResourceNotExisting

public static Resource toResourceNotExisting(PageContext pc,
                                             String destination)
cast a String (argument destination) to a File Object, if destination is not a absolute, file object will be relative to current position (get from PageContext) existing file is prefered but dont must exist

Parameters:
pc - Page Context to et actuell position in filesystem
destination - relative or absolute path for file object
Returns:
file object from destination

toResourceNotExisting

public static Resource toResourceNotExisting(PageContext pc,
                                             String destination,
                                             boolean allowRealpath)

isUNCPath

public static boolean isUNCPath(String path)

toExactResource

public static Resource toExactResource(Resource res)
transalte the path of the file to a existing file path by changing case of letters Works only on Linux, becasue Example Unix: we have a existing file with path "/usr/virtual/myFile.txt" now you call this method with path "/Usr/Virtual/myfile.txt" the result of the method will be "/usr/virtual/myFile.txt" if there are more file with rhe same name but different cases Example: /usr/virtual/myFile.txt /usr/virtual/myfile.txt /Usr/Virtual/myFile.txt the nearest case wil returned

Parameters:
res -
Returns:
file

createResource

public static Resource createResource(Resource res,
                                      short level,
                                      short type)
create a file if possible, return file if ok, otherwise return null

Parameters:
res - file to touch
level - touch also parent and grand parent
type - is file or directory
Returns:
file if exists, otherwise null

setAttribute

public static void setAttribute(Resource res,
                                String attributes)
                         throws IOException
Throws:
IOException

translateAttribute

public static String translateAttribute(String attributes)
                                 throws IOException
sets attributes of a file on Windows system

Parameters:
res -
attributes -
Throws:
PageException
IOException

translatePath

public static String translatePath(String path,
                                   boolean slashAdBegin,
                                   boolean slashAddEnd)

translatePathName

public static String[] translatePathName(String path)
transalte a path in a proper form and cut name away example susi\petere -> /susi/ and peter

Parameters:
path -
Returns:

prettifyPath

public static String prettifyPath(String path)

removeScheme

public static String removeScheme(String scheme,
                                  String path)

merge

public static String merge(String parent,
                           String child)
merge to path parts to one

Parameters:
parent -
child -
Returns:

getCanonicalPathEL

public static String getCanonicalPathEL(Resource res)
Returns the canonical form of this abstract pathname.

Parameters:
res - file to get canoncial form from it
Returns:
The canonical pathname string denoting the same file or directory as this abstract pathname
Throws:
SecurityException - If a required system property value cannot be accessed.

getCanonicalResourceEL

public static Resource getCanonicalResourceEL(Resource res)
Returns the canonical form of this abstract pathname.

Parameters:
res - file to get canoncial form from it
Returns:
The canonical pathname string denoting the same file or directory as this abstract pathname
Throws:
SecurityException - If a required system property value cannot be accessed.

createNewResourceEL

public static boolean createNewResourceEL(Resource res)
creates a new File

Parameters:
res -
Returns:
was successfull

exists

public static boolean exists(Resource res)

canRW

public static boolean canRW(Resource res)
check if file is read and writable

Parameters:
res -
Returns:
is or not

touch

public static void touch(Resource res)
                  throws IOException
similat to linux bash fuction toch, create file if not exist oherwise change last modified date

Parameters:
res -
Throws:
IOException

clear

public static void clear(Resource res)
                  throws IOException
Throws:
IOException

getMimeType

public static String getMimeType(Resource res,
                                 String defaultValue)
return the mime type of a file, dont check extension

Parameters:
res -
defaultValue -
Returns:
mime type of the file

getMimeType

public static String getMimeType(Resource res,
                                 int checkingType,
                                 String defaultValue)

isChildOf

public static boolean isChildOf(Resource file,
                                Resource dir)
check if file is a child of given directory

Parameters:
file - file to search
dir - directory to search
Returns:
is inside or not

getPathToChild

public static String getPathToChild(Resource file,
                                    Resource dir)
return diffrents of one file to a other if first is child of second otherwise return null

Parameters:
file - file to search
dir - directory to search

getExtension

public static String getExtension(Resource res,
                                  String defaultValue)
get the Extension of a file

Parameters:
res -
Returns:
extension of file

getExtension

public static String getExtension(String strFile,
                                  String defaultValue)
get the Extension of a file

Parameters:
strFile -
Returns:
extension of file

getName

public static String getName(String strFileName)

splitFileName

public static String[] splitFileName(String fileName)
split a FileName in Parts

Parameters:
fileName -
Returns:
new String[]{name[,extension]}

changeExtension

public static Resource changeExtension(Resource file,
                                       String newExtension)
change extesnion of file and return new file

Parameters:
file -
newExtension -
Returns:
file with new Extension

deleteContent

public static void deleteContent(Resource src,
                                 ResourceFilter filter)
Parameters:
res - delete the content of a directory

_deleteContent

public static void _deleteContent(Resource src,
                                  ResourceFilter filter,
                                  boolean deleteDirectories)

copyRecursive

public static void copyRecursive(Resource src,
                                 Resource trg)
                          throws IOException
copy a file or directory recursive (with his content)

Parameters:
res - file or directory to delete
Throws:
IOException
FileNotFoundException

copyRecursive

public static void copyRecursive(Resource src,
                                 Resource trg,
                                 ResourceFilter filter)
                          throws IOException
copy a file or directory recursive (with his content)

Parameters:
src -
trg -
filter -
Throws:
IOException
FileNotFoundException

copy

public static void copy(Resource src,
                        Resource trg)
                 throws IOException
Throws:
IOException

removeChildren

public static void removeChildren(Resource res)
                           throws IOException
Throws:
IOException

removeChildren

public static void removeChildren(Resource res,
                                  ResourceNameFilter filter)
                           throws IOException
Throws:
IOException

removeChildren

public static void removeChildren(Resource res,
                                  ResourceFilter filter)
                           throws IOException
Throws:
IOException

removeChildrenEL

public static void removeChildrenEL(Resource res,
                                    ResourceNameFilter filter)

removeChildrenEL

public static void removeChildrenEL(Resource res,
                                    ResourceFilter filter)

removeChildrenEL

public static void removeChildrenEL(Resource res)

removeEL

public static void removeEL(Resource res,
                            boolean force)

createFileEL

public static void createFileEL(Resource res,
                                boolean force)

createDirectoryEL

public static void createDirectoryEL(Resource res,
                                     boolean force)

getContentType

public static ContentType getContentType(Resource resource)

moveTo

public static void moveTo(Resource src,
                          Resource dest)
                   throws IOException
Throws:
IOException

getRealSize

public static long getRealSize(Resource res)
return the size of the Resource, other than method length of Resource this mthod return the size of all files in a directory

Parameters:
collectionDir -
Returns:

getRealSize

public static long getRealSize(Resource res,
                               ResourceFilter filter)
return the size of the Resource, other than method length of Resource this mthod return the size of all files in a directory

Parameters:
collectionDir -
Returns:

isEmpty

public static boolean isEmpty(Resource res)
return if Resource is empty, means is directory and has no children or a empty file, if not exist return false.

Parameters:
res -
Returns:

isEmptyDirectory

public static boolean isEmptyDirectory(Resource res)

isEmptyFile

public static boolean isEmptyFile(Resource res)

toResource

public static Resource toResource(File file)

listResources

public static Resource[] listResources(Resource[] resources,
                                       ResourceFilter filter)
list childrn of all given resources

Parameters:
resources -
Returns:

listResources

public static Resource[] listResources(Resource res,
                                       ResourceFilter filter)

deleteFileOlderThan

public static void deleteFileOlderThan(Resource res,
                                       long date,
                                       ExtensionResourceFilter filter)

checkCreateDirectoryOK

public static void checkCreateDirectoryOK(Resource resource,
                                          boolean createParentWhenNotExists)
                                   throws IOException
check if directory creation is ok with the rules for the Resource interface, to not change this rules.

Parameters:
resource -
createParentWhenNotExists -
Throws:
IOException

checkCreateFileOK

public static void checkCreateFileOK(Resource resource,
                                     boolean createParentWhenNotExists)
                              throws IOException
check if file creating is ok with the rules for the Resource interface, to not change this rules.

Parameters:
resource -
createParentWhenNotExists -
Throws:
IOException

checkCopyToOK

public static void checkCopyToOK(Resource source,
                                 Resource target)
                          throws IOException
check if copying a file is ok with the rules for the Resource interface, to not change this rules.

Parameters:
source -
target -
Throws:
IOException

checkMoveToOK

public static void checkMoveToOK(Resource source,
                                 Resource target)
                          throws IOException
check if moveing a file is ok with the rules for the Resource interface, to not change this rules.

Parameters:
source -
target -
Throws:
IOException

checkGetInputStreamOK

public static void checkGetInputStreamOK(Resource resource)
                                  throws IOException
check if getting a inputstream of the file is ok with the rules for the Resource interface, to not change this rules.

Parameters:
resource -
Throws:
IOException

checkGetOutputStreamOK

public static void checkGetOutputStreamOK(Resource resource)
                                   throws IOException
check if getting a outputstream of the file is ok with the rules for the Resource interface, to not change this rules.

Parameters:
resource -
Throws:
IOException

checkRemoveOK

public static void checkRemoveOK(Resource resource)
                          throws IOException
check if removing the file is ok with the rules for the Resource interface, to not change this rules.

Parameters:
resource -
Throws:
IOException

deleteEmptyFolders

public static void deleteEmptyFolders(Resource res)
                               throws IOException
Throws:
IOException

getResource

public static Resource getResource(PageContext pc,
                                   PageSource ps)
                            throws PageException
Deprecated. use instead PageSource.getResourceTranslated(PageContext)

if the pageSource is based on a archive, translate the source to a zip:// Resource

Parameters:
pc - the Page Context Object
Returns:
return the Resource matching this PageSource
Throws:
PageException

getResource

public static Resource getResource(PageContext pc,
                                   PageSource ps,
                                   Resource defaultValue)

directrySize

public static int directrySize(Resource dir,
                               ResourceFilter filter)

directrySize

public static int directrySize(Resource dir,
                               ResourceNameFilter filter)

names

public static String[] names(Resource[] resources)

merge

public static Resource[] merge(Resource[] srcs,
                               Resource[] trgs)


Copyright © 2012 Railo