|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.nuiton.util.FileUtil
public class FileUtil
Opérations sur des fichiers. Copie, suppression, renommage, recherche, fichiers d'un répertoire, sous-répertoires d'un répertoire, récupération du basename ou de l'extension, création d'un fichier temporaire, comparaison de dates de création, récupération d'une chaîne, d'un Reader ou d'un Writer à partir d'un fichier, récupération du fichier saisi dans une boîte de dialogue, conversions en byte[], en Stream...
Created: 22 novembre 2004
| Nested Class Summary | |
|---|---|
static interface |
FileUtil.FileAction
|
static class |
FileUtil.PatternChooserFilter
|
| Field Summary | |
|---|---|
protected static File |
currentDirectory
|
static String |
ENCODING
Encoding utilisé (peut être redéfini) |
| Constructor Summary | |
|---|---|
FileUtil()
|
|
| Method Summary | |
|---|---|
static String |
basename(File file,
String... suffixes)
Equivalent de la methode basename unix. |
static String |
basename(String name,
String... suffixes)
Equivalent de la methode basename unix. |
static File |
byteToFile(byte[] bytes)
Permet de convertir des bytes en fichier, le fichier sera automatiquement supprimé a la fin de la JVM. |
static File |
byteToFile(byte[] bytes,
File file)
Deprecated. since 2.4.6, prefer use method FileUtils.writeByteArrayToFile(File, byte[]) |
static File |
changeExtension(File file,
String newExtension,
String... extchars)
Recupère le fichier dans le même répertoire que le fichier donné et dont on a changé l'extension. |
static String |
changeExtension(String name,
String newExtension,
String... extchars)
Change l'extension du fichier en entrée avec la nouvelle extension |
static void |
copyAndRenameRecursively(File srcDir,
File destDir,
boolean includeSrcDir,
String renameFrom,
String renameTo,
boolean exclude,
String... includePatterns)
Copie recursivement le repertoire source dans le repertoire destination copyRecursively("/truc/titi", "/var/tmp", "bidulle") donnera le repertoire "/var/tmp/bidulle", 'bidulle' remplacant 'titi' |
static void |
copyAndRenameRecursively(File srcDir,
File destDir,
String renameFrom,
String renameTo,
String... includePatterns)
Copie recursivement le repertoire source dans le repertoire destination copyRecursively("/truc/titi", "/var/tmp", "bidulle") donnera le repertoire "/var/tmp/bidulle", 'bidulle' remplacant 'titi' |
static void |
copyRecursively(File srcDir,
File destDir,
String... includePatterns)
Copie recursivement le repertoire source dans le repertoire destination copyRecursively("/truc/titi", "/var/tmp") donnera le repertoire "/var/tmp/titi" |
static boolean |
createDirectoryIfNecessary(File dir)
Create the directory (and his parents) if necessary. |
static File |
createTempDirectory(String prefix,
String suffix)
Permet de creer un nouveu repertoire temporaire, l'effacement du répertoire est a la charge de l'appelant |
static File |
createTempDirectory(String prefix,
String suffix,
File tmpdir)
Permet de creer un nouveu repertoire temporaire, l'effacement du répertoire est a la charge de l'appelant |
static String |
extension(File file,
String... extchars)
Permet de récupérer l'extension d'un fichier |
static String |
extension(String name,
String... extchars)
Permet de récupérer l'extension d'un nom de fichier |
static List<File> |
find(File directory,
String pattern,
boolean recursively)
Retourne les fichiers d'un répertoire qui satisfont un certain pattern. |
static File |
getCurrentDirectory()
|
static String |
getDirectory()
|
static String |
getDirectory(Component parent,
String title,
String approvalText)
|
static String |
getDirectory(String title,
String approvalText)
|
static File |
getFile(Component parent,
FileFilter... filters)
Retourne le nom du fichier entre dans la boite de dialogue. |
static File |
getFile(Component parent,
String... patternOrDescriptionFilters)
Retourne le nom du fichier entre dans la boite de dialogue. |
static File |
getFile(FileFilter... filters)
Retourne le nom du fichier entre dans la boite de dialogue. |
static File |
getFile(String... patternOrDescriptionFilters)
Retourne le nom du fichier entre dans la boite de dialogue. |
static File |
getFile(String title,
String approvalText,
Component parent,
FileFilter... filters)
Retourne le nom du fichier entre dans la boite de dialogue. |
static File |
getFile(String title,
String approvalText,
Component parent,
String... patternOrDescriptionFilters)
Retourne le nom du fichier entre dans la boite de dialogue. |
static File |
getFileFromFQN(File rootDirectory,
String fqn)
Obtain a file fro the given rootDirectory, applying the fqn. |
static File |
getFileFromPaths(File rootDirectory,
String... paths)
Obtain a file from the given rootDirectory, applying given paths. |
static List<File> |
getFiles(File directory)
Retourne tous les fichiers du répertoire passé en argument. |
static List<File> |
getFilteredElements(File directory,
FileFilter ff,
boolean recursively)
Retourne la liste de toutes les fichiers ou répertoire qui s'attisfont le filtre |
static BufferedReader |
getReader(File file)
Retourne un Reader utilisant l'encoding par defaut ENCODING. |
static BufferedReader |
getReader(File file,
String encoding)
Retourne un reader utilisant l'encoding choisi et placé dans un BufferedReader |
static File |
getRelativeFile(File inputDirectory,
File outputDirectory,
File file)
Recupère le fichier mirroir du fichier file donnée qui est dans
l'arborescence de inputDirectory dans le répertoire
ouputDirectory. |
static List<File> |
getSubDirectories(File directory)
Retourne tous les sous répertoires du répertoire passé en argument. |
static File |
getTempFile(String content)
Permet de donner une representation fichier pour une chaine de caractere. |
static File |
getTempFile(String content,
String fileSuffix)
Permet de donner une representation fichier pour une chaine de caractere. |
static BufferedWriter |
getWriter(File file)
Retourne un Writer utilisant l'encoding par defaut ENCODING. |
static BufferedWriter |
getWriter(File file,
String encoding)
Retourne un writer utilisant l'encoding choisi et placé dans un BufferedWriter |
protected static List<CharSequence> |
grep(String regex,
CharBuffer cb)
Use the linePattern to break the given CharBuffer into lines, applying the input pattern to each line to see if we have a match Code taken from : http://java.sun.com/javase/6/docs/technotes/guides/io/example/Grep.java |
static List<CharSequence> |
grep(String searchRegex,
File f,
String encoding)
Java implementation for the unix grep command. |
static Map<File,List<CharSequence>> |
grep(String searchRegex,
File rootDirectory,
String fileRegex,
String encoding)
Java implementation for the unix grep command. |
static Map<File,List<CharSequence>> |
grep(String searchRegex,
String fileRegex,
String encoding)
Search for files matching regex in current directory. |
static ByteArrayOutputStream |
readBytesFrom(InputStream inputStream,
int defaultBufferSize)
Get a ByteArrayOutputStream containing all data that could be read from the given InputStream |
static void |
sed(String searchRegex,
String replace,
File file,
String encoding)
Sed implementation for a single file. |
static void |
sed(String searchRegex,
String replace,
File rootDirectory,
String fileRegex,
String encoding)
Java implementation for the unix sed command. |
static void |
sed(String searchRegex,
String replace,
String fileRegex,
String encoding)
Java implementation for the unix sed command. |
static void |
setCurrentDirectory(File dir)
|
static boolean |
walkAfter(File f,
FileUtil.FileAction fileAction)
Permet de faire une action avant le parcours des fichiers, c-a-d que l'on fera l'action sur les fichiers contenu dans un répertoire après l'action sur le répertoire lui même. |
static boolean |
walkBefore(File f,
FileUtil.FileAction fileAction)
Permet de faire une action apès le parcours des fichiers, c-a-d que l'on fera l'action sur les fichiers contenu dans un répertoire avant l'action sur le répertoire lui même. |
static void |
writeString(File file,
String content,
String encoding)
Deprecated. since 2.4.6, prefer use method FileUtils.writeStringToFile(File, String, String). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static String ENCODING
protected static File currentDirectory
| Constructor Detail |
|---|
public FileUtil()
| Method Detail |
|---|
public static void setCurrentDirectory(File dir)
public static File getCurrentDirectory()
public static File getFile(String... patternOrDescriptionFilters)
patternOrDescriptionFilters - les filtres a utiliser, les chaines doivent etre données
par deux, le pattern du filtre + la description du filtre
getFile(javax.swing.filechooser.FileFilter...)public static File getFile(FileFilter... filters)
filters - les filtres a ajouter
public static File getFile(Component parent,
String... patternOrDescriptionFilters)
parent - le component parent du dialogpatternOrDescriptionFilters - les filtres a utiliser, les chaines doivent etre données
par deux, le pattern du filtre + la description du filtre
getFile(javax.swing.filechooser.FileFilter...)
public static File getFile(String title,
String approvalText,
Component parent,
String... patternOrDescriptionFilters)
title - le titre de la boite de dialogueapprovalText - le label du boutton d'acceptationparent - le component parent du dialogpatternOrDescriptionFilters - les filtres a utiliser, les chaines doivent etre données
par deux, le pattern du filtre + la description du filtre
getFile(javax.swing.filechooser.FileFilter...)
public static File getFile(Component parent,
FileFilter... filters)
parent - le component parent du dialogfilters - les filtres a ajouter
public static File getFile(String title,
String approvalText,
Component parent,
FileFilter... filters)
title - le titre de la boite de dialogueapprovalText - le label du boutton d'acceptationparent - le component parent du dialogfilters - les filtres a ajouter
public static String getDirectory()
public static String getDirectory(String title,
String approvalText)
title - le nom de la boite de dialogueapprovalText - le texte de l'action d'acceptation du répertoire dans le file chooser
public static String getDirectory(Component parent,
String title,
String approvalText)
parent - le component parent du dialogtitle - le nom de la boite de dialogueapprovalText - le texte de l'action d'acceptation du répertoire dans le file chooser
public static File byteToFile(byte[] bytes)
throws IOException
bytes - the array of bytes to copy in dstination file
IOException - if any io pb
@Deprecated
public static File byteToFile(byte[] bytes,
File file)
throws IOException
FileUtils.writeByteArrayToFile(File, byte[])
bytes - the array of bytes to put in the given destination filefile - le fichier dans lequel il faut ecrire les bytes
IOException - if any io pb
public static BufferedReader getReader(File file)
throws IOException
ENCODING.
file - the given reader
IOException - if any io pb
public static BufferedReader getReader(File file,
String encoding)
throws IOException
file - the given fileencoding - (ISO-8859-1, UTF-8, ...)
IOException - if any io pb
public static BufferedWriter getWriter(File file)
throws IOException
ENCODING.
file - the given file
IOException - if any io pb
public static BufferedWriter getWriter(File file,
String encoding)
throws IOException
file - the given fileencoding - (ISO-8859-1, UTF-8, ...)
IOException - if any io pb
public static File createTempDirectory(String prefix,
String suffix,
File tmpdir)
throws IOException
prefix - le prefix du fichiersuffix - le suffix du fichiertmpdir - le répertoire temporaire ou il faut creer le repertoire
si null on utilise java.io.tmpdir
IOException - if any io pb
public static File createTempDirectory(String prefix,
String suffix)
throws IOException
prefix - le prefix du repertoire a creersuffix - le suffix du repertoire a creer.
IOException - if any io pb
@Deprecated
public static void writeString(File file,
String content,
String encoding)
throws IOException
FileUtils.writeStringToFile(File, String, String).
file - Le fichier dans lequel il faut ecrire la chainecontent - Le texte a ecrire dans le fichierencoding - encoding to use
IOException - if any pb while writing
public static File getTempFile(String content)
throws IOException
content - le contenu du fichier temporaire
IOException - if any io pb
public static File getTempFile(String content,
String fileSuffix)
throws IOException
content - le contenu du fichier temporairefileSuffix - l'extension du fichier créé
IOException - if any io pb
public static String basename(File file,
String... suffixes)
file - le fichier dont on souhaite le nom sans le cheminsuffixes - si present represente le suffixe a eliminer du fichier
s'il est trouvé
public static String basename(String name,
String... suffixes)
name - le nom du fichier dont on souhaite le nom sans le cheminsuffixes - si present represente le suffixe a eliminer du fichier
s'il est trouvé
public static String extension(File file,
String... extchars)
file - le fichier dont on souhaite l'extensionextchars - la liste des caracteres pouvant former l'extension
dans l'ordre de preference. Si vide on utilise ".".
public static String extension(String name,
String... extchars)
name - le nom du fichier dont on souhaite l'extensionextchars - la liste des caracteres pouvant former l'extension
dans l'ordre de preference. Si vide on utilise ".".
public static File changeExtension(File file,
String newExtension,
String... extchars)
throws IOException
file - le fichier d'originenewExtension - la nouvelle extension à utiliserextchars - la liste des extensions possibles
IOException - si aucune extension trouvé dans le fichier d'origine
public static String changeExtension(String name,
String newExtension,
String... extchars)
throws IOException
name - le nom de fichier à transformernewExtension - la nouvelle extension à utiliserextchars - la liste des extensions possibles
IOException - si aucune extension trouvé dans le fichier d'origine
public static File getRelativeFile(File inputDirectory,
File outputDirectory,
File file)
file donnée qui est dans
l'arborescence de inputDirectory dans le répertoire
ouputDirectory.
inputDirectory - le répertoire de départoutputDirectory - le répertoire ciblefile - le fichier
public static List<File> getSubDirectories(File directory)
directory - un répertoire
File de répertoires et ceci
recursivement à partir de directory, si directory
n'est pas un répertoire la liste est vide.public static List<File> getFiles(File directory)
directory - un répertoire
File des fichiers et ceci
recursivement à partir de directory, si directory n'est pas un
répertoire la liste est vide
public static List<File> find(File directory,
String pattern,
boolean recursively)
directory - le répertoire à partir duquel il faut faire la recherchepattern - le pattern que doit respecter le fichier pour être dans la
liste résultanterecursively - flag pour indiquer si on doit descendre dans les sous répertoires
File qui ont s'attisfait le
pattern.
public static List<File> getFilteredElements(File directory,
FileFilter ff,
boolean recursively)
directory - repertoire à partir duquel il faut faire la rechercheff - le filtre à appliquer pour savoir si le fichier parcouru doit
être conservé dans les résultats, ou null pour tous les fichiersrecursively - un flag pour indiquer si on doit descendre dans les répertoires
File, qui s'attisfont le filtre
public static boolean walkAfter(File f,
FileUtil.FileAction fileAction)
f - le fichier ou répertoire à partir duquel il faut commencerfileAction - l'action à effectuer sur chaque fichier
public static boolean walkBefore(File f,
FileUtil.FileAction fileAction)
f - le fichier ou répertoire à partir duquel il faut commencerfileAction - l'action à effectuer sur chaque fichier
public static void copyRecursively(File srcDir,
File destDir,
String... includePatterns)
throws IOException
srcDir - le répertoire source à copierdestDir - le répertoire destination où copierincludePatterns - les patterns que doivent resperter les
fichiers/repertoires pour etre copié. Si vide alors tout est copié
IOException - if any io pb
public static void copyAndRenameRecursively(File srcDir,
File destDir,
String renameFrom,
String renameTo,
String... includePatterns)
throws IOException
srcDir - le répertoire source à copierdestDir - le répertoire destination où copierrenameFrom - pattern to permit rename file before uncompress itrenameTo - new name for file if renameFrom is applicable to it
you can use $1, $2, ... if you have '(' ')' in renameFromincludePatterns - les patterns que doivent resperter les
fichiers/repertoires pour etre copié. Si vide alors tout est copié
IOException - if any io pb
public static void copyAndRenameRecursively(File srcDir,
File destDir,
boolean includeSrcDir,
String renameFrom,
String renameTo,
boolean exclude,
String... includePatterns)
throws IOException
srcDir - le répertoire source à copierdestDir - le répertoire destination où copierincludeSrcDir - si vrai alors le repertoire source est copie dans le
repertoire destination et non pas seulement les fichiers qu'il contientrenameFrom - pattern to permit rename file before uncompress itrenameTo - new name for file if renameFrom is applicable to it
you can use $1, $2, ... if you have '(' ')' in renameFromexclude - inverse include pattern interpretationincludePatterns - les patterns que doivent resperter les
fichiers/repertoires pour etre copié. Si vide alors tout est copié
IOException - if any io pb
public static ByteArrayOutputStream readBytesFrom(InputStream inputStream,
int defaultBufferSize)
throws IOException
inputStream - the stream to readdefaultBufferSize - the buffer size
IOException - if any pb while reading or writing
protected static List<CharSequence> grep(String regex,
CharBuffer cb)
regex - regex to search into filecb - nio buffer
IOException
public static List<CharSequence> grep(String searchRegex,
File f,
String encoding)
throws IOException
searchRegex - regex to search into filef - file to search intoencoding - encoding to use
IOException
public static Map<File,List<CharSequence>> grep(String searchRegex,
File rootDirectory,
String fileRegex,
String encoding)
throws IOException
searchRegex - regex to search into filerootDirectory - directory to seacrh intofileRegex - regex for file to find in rootDirectoryencoding - encoding to use
IOException
public static Map<File,List<CharSequence>> grep(String searchRegex,
String fileRegex,
String encoding)
throws IOException
searchRegex - regex to search into filefileRegex - regex for file to find in current direncoding - encoding to use
IOException
public static void sed(String searchRegex,
String replace,
File file,
String encoding)
throws IOException
searchRegex - Prefix which shall be replacedreplace - Prefix which is going to replace the originalfile - File which sed shall be appliedencoding - charset encoding
IOException
public static void sed(String searchRegex,
String replace,
File rootDirectory,
String fileRegex,
String encoding)
throws IOException
searchRegex - regex to search into filereplace - string to replace matching patternsrootDirectory - directory to search intofileRegex - regex for file to find in rootDirectoryencoding - encoding to use
IOException
public static void sed(String searchRegex,
String replace,
String fileRegex,
String encoding)
throws IOException
searchRegex - regex to search into filereplace - string to replace matching patternsfileRegex - regex for file to find in current direncoding - encoding to use
IOException
public static boolean createDirectoryIfNecessary(File dir)
throws IOException
dir - the directory to create if not exisiting
true if directory was created, false if was no
need to create it
IOException - if could not create directory
public static File getFileFromPaths(File rootDirectory,
String... paths)
rootDirectory, applying given paths.
For example with paths = a, b and c, then result is :
root/a/b/c
rootDirectory - the root directorypaths - paths to apply
public static File getFileFromFQN(File rootDirectory,
String fqn)
rootDirectory, applying the fqn.
For example with fqn = a.b.c, the result is :
root/a/b/c
rootDirectory - the root directoryfqn - fqn of searched file
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||