|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.silverpeas.util.FileUtil
public class FileUtil
Field Summary | |
---|---|
static String |
BASE_CONTEXT
|
static String |
CONTEXT_TOKEN
|
Method Summary | |
---|---|
static void |
checkPathNotRelative(String path)
Checking that the path doesn't contain relative navigation between pathes. |
static String |
convertBundleName(String bundle)
Utility method for migration of Silverpeas configuration from : com.silverpeas, com.stratelia.silverpeas, com.stratelia.webactiv to org.silverpeas |
static String |
convertFilePath(File file)
|
static String |
convertPathToServerOS(String undeterminedOsPath)
Convert a path to the current OS path format. |
static String |
convertResourceName(String resource)
Utility method for migration of Silverpeas configuration from : com/silverpeas, com/stratelia/silverpeas, com/stratelia/webactiv to org/silverpeas |
static void |
copyFile(File source,
File destination)
Copies the specified source file to the specified destination. |
static boolean |
deleteEmptyDir(File directory)
|
static void |
forceDeletion(File fileToDelete)
Forces the deletion of the specified file. |
static String[] |
getAttachmentContext(String context)
Create the array of strings this array represents the repertories where the files must be stored. |
static String |
getFilename(String fileName)
|
static String |
getMimeType(String fileName)
Detects the mime-type of the specified file. |
static boolean |
isArchive(String filename)
Indicates if the current file is of type archive. |
static boolean |
isFileSecure(String fileName,
String intendedDir)
|
static boolean |
isImage(String filename)
Indicates if the current file is of type image. |
static boolean |
isMail(String filename)
Indicates if the current file is of type mail. |
static boolean |
isOpenOfficeCompatible(String filename)
|
static boolean |
isPdf(String filename)
Indicates if the current file is of type PDF. |
static boolean |
isSpinfireDocument(String filename)
If 3D document. |
static boolean |
isWindows()
Indicates if the OS is from the Microsoft Windows familly |
static Collection<File> |
listFiles(File directory,
String[] extensions,
boolean recursive)
|
static Collection<File> |
listFiles(File directory,
String[] extensions,
boolean caseSensitive,
boolean recursive)
|
static ResourceBundle |
loadBundle(String bundleName,
Locale locale)
Loads a ResourceBundle from the Silverpeas configuration directory. |
static void |
loadProperties(Properties properties,
String resourceName)
Loads loads the resource into the specified properties. |
static File[] |
moveAllFilesAtRootFolder(File rootFolder)
Moves all files from sub folders to the given root folder and deletes after all the sub folders. |
static File[] |
moveAllFilesAtRootFolder(File rootFolder,
boolean deleteFolders)
Moves all files from sub folders to the given root folder. |
static void |
moveFile(File source,
File destination)
Moves the specified source file to the specified destination. |
static byte[] |
readFile(File file)
Read the content of a file in a byte array. |
static String |
readFileToString(File file)
Read the content of a file as text (the text is supposed to be in the UTF-8 charset). |
static String |
validateFilename(String fileName,
String intendedDir)
Validate that fileName given in parameter is inside extraction target directory (intendedDir) |
static void |
writeFile(File file,
InputStream data)
Write a stream into a file. |
static void |
writeFile(File file,
Reader data)
Write a stream into a file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String CONTEXT_TOKEN
public static final String BASE_CONTEXT
Method Detail |
---|
public static String convertBundleName(String bundle)
bundle
- the name of the bundle.
public static String convertResourceName(String resource)
resource
- the name of the resource.
public static String getMimeType(String fileName)
fileName
- the name of the file with its path.
public static String[] getAttachmentContext(String context)
context
-
public static byte[] readFile(File file) throws IOException
file
- the file to be read.
IOException
public static String readFileToString(File file) throws IOException
file
- the file to read.
IOException
- if an error occurs while reading the file.public static void writeFile(File file, InputStream data) throws IOException
file
- the file to be written.data
- the data to be written.
IOException
public static void writeFile(File file, Reader data) throws IOException
file
- the file to be written.data
- the data to be written.
IOException
public static ResourceBundle loadBundle(String bundleName, Locale locale)
bundleName
- the name of the bundle.locale
- the locale of the bundle.
public static void loadProperties(Properties properties, String resourceName) throws IOException
properties
- the properties to be loaded with the resource.resourceName
- the name of the resource.
IOException
public static boolean isWindows()
public static boolean isSpinfireDocument(String filename)
filename
- the name of the file.
public static boolean isArchive(String filename)
filename
- the name of the file.
public static boolean isImage(String filename)
filename
- the name of the file.
public static boolean isMail(String filename)
filename
- the name of the file.
public static boolean isPdf(String filename)
filename
- the name of the file.
public static boolean isOpenOfficeCompatible(String filename)
public static void checkPathNotRelative(String path) throws RelativeFileAccessException
path
-
RelativeFileAccessException
public static Collection<File> listFiles(File directory, String[] extensions, boolean recursive)
public static Collection<File> listFiles(File directory, String[] extensions, boolean caseSensitive, boolean recursive)
public static void forceDeletion(File fileToDelete) throws IOException
fileToDelete
- file to delete.
IOException
- if the deletion failed or if the file doesn't exist.public static void moveFile(File source, File destination) throws IOException
source
- the file to move.destination
- the destination file of the move.
IOException
- if the source or the destination is invalid or if an error occurs while
moving the file.public static void copyFile(File source, File destination) throws IOException
source
- the file to copy.destination
- the destination file of the move.
IOException
- if the source or the destination is invalid or if an error occurs while
copying the file.public static String getFilename(String fileName)
public static String convertPathToServerOS(String undeterminedOsPath)
undeterminedOsPath
-
public static String convertFilePath(File file)
public static boolean deleteEmptyDir(File directory)
public static File[] moveAllFilesAtRootFolder(File rootFolder) throws IOException
rootFolder
- the root folder from which the sub folders are retrieved and into which the
files will be moved if any.
File
that represents the found sub folders. The returned array is
never null.
IOException
public static File[] moveAllFilesAtRootFolder(File rootFolder, boolean deleteFolders) throws IOException
rootFolder
- the root folder from which the sub folders are retrieved and into which the
files will be moved if any.deleteFolders
- true if the sub folders must be deleted.
File
that represents the found sub folders. The returned array is
never null.
IOException
public static String validateFilename(String fileName, String intendedDir) throws IOException
fileName
- the file name to extractintendedDir
- the extraction target directory
IOException
- if fileName is outside extraction target directorypublic static boolean isFileSecure(String fileName, String intendedDir)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |