|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectfr.tireme.shared.FileUtils
public class FileUtils
File utilities. Note: a lot of the provided code here has been extracted and modified from the org.apache.tools.ant.util.FileUtils and org.apache.tools.ant.taskdefs.Replace classes.
| Field Summary | |
|---|---|
static java.lang.String |
LINE_SEP
the line separator for this OS. |
| Constructor Summary | |
|---|---|
FileUtils()
Constructor for non static methods |
|
| Method Summary | |
|---|---|
java.io.File |
createTempFile(java.lang.String prefix,
java.lang.String suffix,
java.io.File parentDir)
Create a temporary file in a given directory. |
static void |
fileCopy(java.io.File from,
java.io.File to)
Copy a file onto the filesystem |
static void |
fileCopy(java.lang.String from,
java.lang.String to)
Copy a file onto the filesystem |
boolean |
fileNameEquals(java.io.File f1,
java.io.File f2)
Compares two filenames. |
java.net.URL |
getFileURL(java.io.File file)
Get the URL for a file taking into account # characters |
java.io.File |
getParentFile(java.io.File f)
Emulation of File.getParentFile for JDK 1.1 |
static java.io.File |
getTempDir()
Get the temporary directory |
static java.io.File |
makeFile(java.io.File mainFileDir,
java.lang.String href)
Creates |
static java.io.File |
normalize(java.lang.String path)
"normalize" the given absolute path. |
static java.lang.String |
normalizeAndValidateFile(java.lang.String fileName)
Normalize a file according to system specificities and validate if exists |
static java.lang.String |
normalizeAndValidateFile(java.lang.String fileName,
boolean asURL)
Normalize a file according to system specificities and validate if exists |
static java.lang.String |
normalizeFile(java.lang.String fileName)
Normalize a file according to system specificities |
static void |
printToFile(java.lang.String result,
java.lang.String fileName)
|
java.lang.StringBuffer |
readFile(java.lang.String confPath)
readFile gets the StringBuffer of a file from the passed file path. |
java.lang.String |
readFileAsString(java.io.File file)
Méthode de conversion de fichier en STRING |
void |
rename(java.io.File from,
java.io.File to)
Renames a file, even if that involves crossing file system boundaries. |
boolean |
replaceStringInFile(java.io.File src,
java.lang.String token,
java.lang.String value)
Perform replacement on a given file. |
boolean |
storeFile(java.lang.String filePath,
java.lang.String file)
storeFile takes a path name plus a String content and creates the corresponding file. important: if the file already exists, its content will be overwritten by the new content |
static java.lang.String |
toURI(java.lang.String path)
Constructs a file: URI that represents the external form of the given pathname. |
void |
writeStringasFile(java.io.File file,
java.lang.String text)
Méthode d'écriture d'un texte dans un fichier |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String LINE_SEP
| Constructor Detail |
|---|
public FileUtils()
| Method Detail |
|---|
public static void fileCopy(java.io.File from,
java.io.File to)
throws StandardException
from - source pathto - destination path
StandardException - All exceptions found
public static void fileCopy(java.lang.String from,
java.lang.String to)
throws StandardException
from - source pathto - destination path
StandardException - All exceptions foundpublic static java.io.File getTempDir()
public static java.io.File makeFile(java.io.File mainFileDir,
java.lang.String href)
throws java.io.FileNotFoundException,
java.io.IOException
mainFileDir - Filehref - String
java.io.FileNotFoundException
java.io.IOException
public static java.io.File normalize(java.lang.String path)
throws StandardException
This includes:
File#getCanonicalPath() it specifically doesn't resolve symbolic links.
path - the path to be normalized
StandardException - if the file path is equal to null.
public static java.lang.String normalizeAndValidateFile(java.lang.String fileName)
throws StandardException
fileName - file name to be normalized
StandardException - raised if file does not exists.
public static java.lang.String normalizeAndValidateFile(java.lang.String fileName,
boolean asURL)
throws StandardException
fileName - file name to be normalizedasURL - want result as an URI
StandardException - raised if file does not exists.
public static java.lang.String normalizeFile(java.lang.String fileName)
throws StandardException
fileName - file name to be normalized
StandardException - Description of Exception
public static void printToFile(java.lang.String result,
java.lang.String fileName)
throws StandardException
result - data to be printedfileName - Description of Parameter
StandardException - All exceptions foundpublic static java.lang.String toURI(java.lang.String path)
file: URI that represents the external form of the given pathname.
Will be an absolute URI if the given path is absolute.
This code doesn't handle non-ASCII characters properly.
path - the path in the local file system
public java.io.File createTempFile(java.lang.String prefix,
java.lang.String suffix,
java.io.File parentDir)
The file denoted by the returned abstract pathname did not exist before this method was invoked, any subsequent invocation of this method will yield a different file name.
This method is different to File.createTempFile of JDK 1.2 as it doesn't create the file itself. It uses the location pointed to by java.io.tmpdir when the parentDir attribute is null.
prefix - prefix to add to filenamesuffix - suffix to add to filenameparentDir - Directory to create the temporary file in - current working directory will be assumed if this
parameter is null.
public boolean fileNameEquals(java.io.File f1,
java.io.File f2)
throws StandardException
Unlike java.io.File#equals this method will try to compare the absolute paths and "normalize" the filenames before comparing them.
f1 - the file whose name is to be compared.f2 - the other file whose name is to be compared.
StandardException
public java.net.URL getFileURL(java.io.File file)
throws java.net.MalformedURLException
file - the file whose URL representation is required.
java.net.MalformedURLException - if the URL representation cannot be formed.public java.io.File getParentFile(java.io.File f)
f - the file whose parent is required.
public java.lang.StringBuffer readFile(java.lang.String confPath)
throws java.io.FileNotFoundException
confPath - file's path
java.io.FileNotFoundException
public void rename(java.io.File from,
java.io.File to)
throws java.io.IOException,
StandardException
This will remove to (if it exists), ensure that to's parent directory exists and
move from, which involves deleting from as well.
from - the file to moveto - the new file name
java.io.IOException - if anything bad happens during this process. Note that to may have been
deleted already when this happens.
StandardException
public java.lang.String readFileAsString(java.io.File file)
throws java.io.IOException
file - File Le fichier à convertir
java.io.IOException - L'exception sur l'accés au fichier
public void writeStringasFile(java.io.File file,
java.lang.String text)
throws java.io.IOException
file - le fichier à complétertext - le texte a ajouter
java.io.IOException - L'exception sur l'accés du fichier
public boolean replaceStringInFile(java.io.File src,
java.lang.String token,
java.lang.String value)
throws StandardException
src - the source filetoken - string to searchvalue - replacement string
StandardException
public boolean storeFile(java.lang.String filePath,
java.lang.String file)
filePath - file's full pathfile - file's content
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||