net.sf.mmapps.commons.util
Class FileUtil

java.lang.Object
  extended by net.sf.mmapps.commons.util.FileUtil

public class FileUtil
extends java.lang.Object


Nested Class Summary
static class FileUtil.DirectoryOnlyFilter
           
static class FileUtil.FileOnlyFilter
           
static class FileUtil.IgnoreFilter
          The directory filter class is used to filter files in a directory based on whether the child itself is a directory or not.
 
Constructor Summary
FileUtil()
           
 
Method Summary
static boolean checkFileExists(java.lang.String fileName)
           
static boolean checkFileNameCaseSensitive(java.lang.String path)
          check if a file or directory exists on disk.
static void copyFolderContent(java.lang.String origin, java.lang.String destination, java.io.FileFilter filter)
          Copy files from String origin to String destination.
static void copyStream(java.io.InputStream inputStream, java.io.OutputStream outputStream)
          Copy an InputStream to an OutputStream
static boolean deleteFile(java.io.File f)
          delete a file or directory (and all its content)
static boolean deleteFile(java.io.File f, boolean contentOnly)
          delete a file or directory ( and all its contains )
 java.io.File[] getChildFiles(java.lang.String path)
          Get all the child files (i.e. no directories) for a given relative path.
 java.io.File getFileFromPath(java.lang.String path)
          Given a path relative to the staging root, fetch the file.
static java.io.InputStream getInputStream(java.lang.String fileName)
           
 java.io.File getParent(java.io.File child)
          Get the parent of a specific child folder
 java.lang.String getPathFromFile(java.io.File file, boolean urlEncode)
          Get the path of a directory or file relative to the root.
static void moveFolderContent(java.lang.String origin, java.lang.String destination, java.io.FileFilter filter)
          Move files from String origin to String destination.
static java.lang.String readString(java.lang.String name)
           
static java.lang.String readString(java.lang.String name, int skiplines, boolean keepLines)
           
static java.lang.String removeFileExtension(java.lang.String filename, java.lang.String ext)
          Return the file name but without the extension
static void writeBytesInFile(java.lang.String fileName, byte[] bytes)
           
static void writeFileInFile(java.lang.String fileName, java.lang.String destinationFile)
           
static void writeStreamInFile(java.lang.String fileName, java.io.InputStream input)
           
static void writeStringInFile(java.lang.String fileName, java.lang.String output)
          Write a string in a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

readString

public static java.lang.String readString(java.lang.String name)

readString

public static java.lang.String readString(java.lang.String name,
                                          int skiplines,
                                          boolean keepLines)

moveFolderContent

public static void moveFolderContent(java.lang.String origin,
                                     java.lang.String destination,
                                     java.io.FileFilter filter)
                              throws java.io.IOException
Move files from String origin to String destination.

Parameters:
origin - original folder
destination - destination folder
filter - move only matching files
Throws:
java.io.IOException - when an error occurs

copyFolderContent

public static void copyFolderContent(java.lang.String origin,
                                     java.lang.String destination,
                                     java.io.FileFilter filter)
                              throws java.io.IOException
Copy files from String origin to String destination.

Parameters:
origin - original folder
destination - destination folder
filter - move only matching files
Throws:
java.io.IOException - when an error occurs

writeStringInFile

public static void writeStringInFile(java.lang.String fileName,
                                     java.lang.String output)
Write a string in a file.

Parameters:
fileName - File name.
output - String output.

writeFileInFile

public static void writeFileInFile(java.lang.String fileName,
                                   java.lang.String destinationFile)
                            throws java.io.IOException
Throws:
java.io.IOException

getInputStream

public static java.io.InputStream getInputStream(java.lang.String fileName)
                                          throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException

writeBytesInFile

public static void writeBytesInFile(java.lang.String fileName,
                                    byte[] bytes)
                             throws java.io.IOException
Throws:
java.io.IOException

writeStreamInFile

public static void writeStreamInFile(java.lang.String fileName,
                                     java.io.InputStream input)
                              throws java.io.IOException
Throws:
java.io.IOException

copyStream

public static void copyStream(java.io.InputStream inputStream,
                              java.io.OutputStream outputStream)
                       throws java.io.IOException
Copy an InputStream to an OutputStream

Parameters:
inputStream - input
outputStream - output
Throws:
java.io.IOException - when an error occurs

checkFileExists

public static boolean checkFileExists(java.lang.String fileName)

checkFileNameCaseSensitive

public static boolean checkFileNameCaseSensitive(java.lang.String path)
check if a file or directory exists on disk. The check is case sensitive

Parameters:
path - the absolute path
Returns:
boolean true if comparison is success

deleteFile

public static boolean deleteFile(java.io.File f)
delete a file or directory (and all its content)

Parameters:
f - the abstract file object
Returns:
completed without errors

deleteFile

public static boolean deleteFile(java.io.File f,
                                 boolean contentOnly)
delete a file or directory ( and all its contains )

Parameters:
f - the abstract file object
contentOnly - id true, delete only the folder content
Returns:
completed without errors

removeFileExtension

public static java.lang.String removeFileExtension(java.lang.String filename,
                                                   java.lang.String ext)
Return the file name but without the extension

Parameters:
filename - the complete file name with extension
ext - the extension to remove @return(String) the filename without a gived extension
Returns:
filename without extension

getParent

public java.io.File getParent(java.io.File child)
Get the parent of a specific child folder

Parameters:
child - Child whose parent is to be retrieved
Returns:
Parent folder of the specified child.

getChildFiles

public java.io.File[] getChildFiles(java.lang.String path)
Get all the child files (i.e. no directories) for a given relative path.

Parameters:
path - Path of files to retrieve.
Returns:
Returns an array of child File objects.

getPathFromFile

public java.lang.String getPathFromFile(java.io.File file,
                                        boolean urlEncode)
Get the path of a directory or file relative to the root.

Parameters:
file - File whose path is to be retrieved.
urlEncode - If set to true, the returned path will be URL encoded.
Returns:
Returns the path of the specified file relative to the repository root.

getFileFromPath

public java.io.File getFileFromPath(java.lang.String path)
Given a path relative to the staging root, fetch the file.

Parameters:
path - Path of file to retrieve.
Returns:
Retuns the File for the given path in the staging repository.


Copyright © 2003-2006 mmapps. All Rights Reserved.