[Lutinutil-commits] r952 - in trunk: lutinutil/src/main/java/org/codelutin/util lutinutil-io/src/main/java/org/codelutin/util
Author: tchemit Date: 2008-07-31 20:35:40 +0000 (Thu, 31 Jul 2008) New Revision: 952 Added: trunk/lutinutil-io/src/main/java/org/codelutin/util/CollectionUtil.java trunk/lutinutil-io/src/main/java/org/codelutin/util/FileUtil.java trunk/lutinutil-io/src/main/java/org/codelutin/util/PropertiesDateRemoveFilterStream.java trunk/lutinutil-io/src/main/java/org/codelutin/util/SortedProperties.java trunk/lutinutil-io/src/main/java/org/codelutin/util/StringUtil.java trunk/lutinutil-io/src/main/java/org/codelutin/util/StringUtilException.java Removed: trunk/lutinutil/src/main/java/org/codelutin/util/CollectionUtil.java trunk/lutinutil/src/main/java/org/codelutin/util/FileUtil.java trunk/lutinutil/src/main/java/org/codelutin/util/PropertiesDateRemoveFilterStream.java trunk/lutinutil/src/main/java/org/codelutin/util/SortedProperties.java trunk/lutinutil/src/main/java/org/codelutin/util/StringUtil.java trunk/lutinutil/src/main/java/org/codelutin/util/StringUtilException.java Log: mise en place de org.codelutin:lutinutil-io qui vien t de lutinutil mais ne permet aucune traduction i18n. ceci est fait pour casser le cycle entre le projet maven-i18n-plugin et lutinutil. lutinutil va d?\195?\169pendre de ce projet donc grace aux dependances transitives, cela reste transparent pour le reste des projets. Deleted: trunk/lutinutil/src/main/java/org/codelutin/util/CollectionUtil.java =================================================================== --- trunk/lutinutil/src/main/java/org/codelutin/util/CollectionUtil.java 2008-07-31 20:12:39 UTC (rev 951) +++ trunk/lutinutil/src/main/java/org/codelutin/util/CollectionUtil.java 2008-07-31 20:35:40 UTC (rev 952) @@ -1,156 +0,0 @@ -/* *##% - * Copyright (C) 2006 - * Code Lutin, C�dric Pineau, Benjamin Poussin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * CollectionUtil.java - * - * Created: 23 f�vr. 2006 09:03:39 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package org.codelutin.util; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - - -/** - * @author poussin - * - */ - -public class CollectionUtil { - - /** - * Ajoute a la collection tous les elements pass�s en parametre - * @param col la collection - * @param e les elements a ajouter - * @return la collection pass� en parametre - */ - static public <A, E extends Collection<A>> E addAll(E col, A ... e) { - Collections.addAll(col, e); - return col; - } - - /** - * Ajoute a la liste tous les elements pass�s en parametre - * @param col la liste - * @param pos le premier index o� ins�rer les donn�es - * @param e les elements a ajouter - * @return la liste pass� en parametre - */ - static public <A, E extends List<A>> E addAll(E col, int pos, A ... e) { - col.addAll(pos, Arrays.asList(e)); - return col; - } - - /** - * Permet de convertir une liste non typ�e, en une liste typ�e. - * - * La liste en entr�e en juste bien cast�e. - * - * On effectue une v�rification sur le typage des �lements de la liste. - * - * Note : <b>Aucune liste n'est cr�ee, ni recopi�e</b> - * - * @param list la liste � convertir - * @param type le type des �l�ments de la liste - * @return la liste typ�e - * @throws IllegalArgumentException si un �l�ment de la liste en entr�e n'est - * pas en ad�quation avec le type voulue. - */ - @SuppressWarnings({"unchecked"}) - static public <O> List<O> toGenericList(List list,Class<O> type) throws IllegalArgumentException { - if (list.isEmpty()) { - return list; - } - for (Object o : list) { - if (!(type.isAssignableFrom(o.getClass()))) { - throw new IllegalArgumentException("can not cast List with object of type "+o.getClass()+" to "+type+" type!"); - } - } - return list; - } - - /** - * Permet de convertir une collection non typ�e, en une collection typ�e. - * - * La collection en entr�e en juste bien cast�e. - * - * On effectue une v�rification sur le typage des �lements de la collection. - * - * Note : <b>Aucune collection n'est cr�ee, ni recopi�e</b> - * - * @param list la collection � convertir - * @param type le type des �l�ments de la collection - * @return la collection typ�e - * @throws IllegalArgumentException si un �l�ment de la collection en entr�e n'est - * pas en ad�quation avec le type voulue. - */ - @SuppressWarnings({"unchecked"}) - static public <O> Collection<O> toGenericCollection(Collection list,Class<O> type) throws IllegalArgumentException { - if (list.isEmpty()) { - return list; - } - for (Object o : list) { - if (!(type.isAssignableFrom(o.getClass()))) { - throw new IllegalArgumentException("can not cast Collection with object of type "+o.getClass()+" to "+type+" type!"); - } - } - return list; - } - - /** - * Permet de convertir un ensemble non typ�e, en un ensemble typ�e. - * - * L'ensemble en entr�e en juste bien cast�e. - * - * On effectue une v�rification sur le typage des �lements de la collection. - * - * Note : <b>Aucun ensemble n'est cr�ee, ni recopi�e</b> - * - * @param list l'ensemble � convertir - * @param type le type des �l�ments de l'ensemble - * @return l'ensemble typ�e - * @throws IllegalArgumentException si un �l�ment de l'ensemble en entr�e n'est - * pas en ad�quation avec le type voulue. - */ - @SuppressWarnings({"unchecked"}) - static public <O> Set<O> toGenericSet(Set list,Class<O> type) throws IllegalArgumentException { - if (list.isEmpty()) { - return list; - } - for (Object o : list) { - if (!(type.isAssignableFrom(o.getClass()))) { - throw new IllegalArgumentException("can not cast Set with object of type "+o.getClass()+" to "+type+" type!"); - } - } - return list; - } -} - - Deleted: trunk/lutinutil/src/main/java/org/codelutin/util/FileUtil.java =================================================================== --- trunk/lutinutil/src/main/java/org/codelutin/util/FileUtil.java 2008-07-31 20:12:39 UTC (rev 951) +++ trunk/lutinutil/src/main/java/org/codelutin/util/FileUtil.java 2008-07-31 20:35:40 UTC (rev 952) @@ -1,766 +0,0 @@ -/* *##% - * Copyright (C) 2002, 2003, 2004 Code Lutin, C�dric Pineau, - * Benjamin Poussin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * FileUtil.java - * - * Created: 22 nov. 2004 - * - * @author Benjamin Poussin <poussin@codelutin.com> - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - -package org.codelutin.util; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileFilter; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.nio.channels.FileChannel; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -import javax.swing.JFileChooser; - -import org.apache.commons.logging.LogFactory; - -public class FileUtil { // FileUtil - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private org.apache.commons.logging.Log log = LogFactory.getLog(FileUtil.class); - - /** Encoding par defaut utilis� si non sp�cifi� */ - static public String ENCODING = "ISO-8859-1"; - static protected File currentDirectory = new File("."); - - static public void setCurrentDirectory(File dir){ - currentDirectory = dir; - } - - static public class PatternChooserFilter extends javax.swing.filechooser.FileFilter { - protected String pattern = null; - protected String description = null; - - public PatternChooserFilter(String pattern, String description) { - this.pattern = pattern; - this.description = description; - } - - @Override - public boolean accept(File f) { - return f.isDirectory() || f.getAbsolutePath().matches(pattern); - } - @Override - public String getDescription() { - return description; - } - - } - - - /** - * Retourne le nom du fichier entre dans la boite de dialogue. - * Si le bouton annuler est utilis�, ou qu'il y a une erreur retourne null. - * - * @param patternOrDescriptionFilters les filtres a utiliser, les chaines doivent etre donn�es - * par deux, le pattern du filtre + la description du filtre - * @return - * - * @see #getFile(javax.swing.filechooser.FileFilter[]) - */ - static public File getFile(String ... patternOrDescriptionFilters) { - if (patternOrDescriptionFilters.length % 2 != 0) { - throw new IllegalArgumentException("Arguments must be (pattern, description) couple"); - } - javax.swing.filechooser.FileFilter [] filters = new javax.swing.filechooser.FileFilter[patternOrDescriptionFilters.length / 2]; - for (int i=0; i<filters.length; i++) { - String pattern = patternOrDescriptionFilters[i*2]; - String description = patternOrDescriptionFilters[i*2 + 1]; - filters[i] = new PatternChooserFilter(pattern, description); - } - File result; - result = getFile(filters); - return result; - } - - /** - * Retourne le nom du fichier entre dans la boite de dialogue. - * Si le bouton annuler est utilis�, ou qu'il y a une erreur retourne null. - * - * @param filters les filtres a ajouter - * @return - */ - static public File getFile(javax.swing.filechooser.FileFilter ... filters){ - try{ - JFileChooser chooser = new JFileChooser(currentDirectory); - - chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); - if (filters.length > 0) { - if (filters.length == 1) { - chooser.setFileFilter(filters[0]); - } else { - for (javax.swing.filechooser.FileFilter filter : filters) { - chooser.addChoosableFileFilter(filter); - } - } - } - chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - int returnVal = chooser.showDialog(null, "Ok"); - if(returnVal == JFileChooser.APPROVE_OPTION) { - File theFile = chooser.getSelectedFile(); - if(theFile != null) { - currentDirectory = theFile; - return theFile.getAbsoluteFile(); - } - } - } - catch(Exception eee){ - log.warn("Erreur:", eee); - } - return null; - } - - /** - * @param title le nom de la boite de dialogue - * @param approvalText - * @return le nom du repertoire entre dans la boite de dialogue. - * Si le bouton annuler est utilis�, ou qu'il y a une erreur retourne - * null. - */ - static public String getDirectory(String title,String approvalText) { - try{ - JFileChooser chooser = new JFileChooser(currentDirectory); - chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - chooser.setDialogTitle(title); - int returnVal = chooser.showDialog(null,approvalText); - if(returnVal == JFileChooser.APPROVE_OPTION) { - File theFile = chooser.getSelectedFile(); - if(theFile != null) { - currentDirectory = theFile; - if(theFile.isDirectory()) { - return theFile.getAbsolutePath(); - } - } - } - else{ - return null; - } - } catch(Exception eee){ - log.warn("Erreur:", eee); - } - return null; - } - - /** - * @return le nom du repertoire entre dans la boite de dialogue. - * Si le bouton annuler est utilis�, ou qu'il y a une erreur retourne - * null. - */ - static public String getDirectory() { - return getDirectory("Ok","Ok"); - } - - /** - * Permet de convertir un fichier en un tableau de byte - * - * @param file - * @return - * @throws IOException - */ - static public byte[] fileToByte(File file) throws IOException { - InputStream in = new BufferedInputStream(new FileInputStream(file)); - ByteArrayOutputStream result = new ByteArrayOutputStream(); - BufferedOutputStream tmp = new BufferedOutputStream(result); - for (int b=in.read(); b != -1; b=in.read()) { - tmp.write(b); - } - in.close(); - tmp.close(); - - return result.toByteArray(); - } - - /** - * Permet de convertir des bytes en fichier, le fichier sera automatiquement - * supprim� a la fin de la JVM. - * - * @param bytes - * @return le fichier temporaire contenant les bytes - * @throws IOException - */ - static public File byteToFile(byte[] bytes) throws IOException { - File file = File.createTempFile("FileUtil-byteToFile", ".tmp"); - byteToFile(bytes, file); - return file; - } - - /** - * Permet de convertir des bytes en fichier - * - * @param bytes - * @param file le fichier dans lequel il faut ecrire les bytes - * @return le fichier pass� en parametre - * @throws IOException - */ - static public File byteToFile(byte[] bytes, File file) throws IOException { - OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); - out.write(bytes); - out.close(); - return file; - } - - /** - * Retourne un Reader utilisant l'encoding par defaut {@link #ENCODING} - * - * @param file - * @return - * @throws IOException - */ - static public BufferedReader getReader(File file) throws IOException { - return getReader(file, ENCODING); - } - - /** - * Retourne un reader utilisant l'encoding choisi et plac� dans un - * BufferedReader - * - * @param file - * @param encoding (ISO-8859-1, UTF-8, ...) - * @return - * @throws IOException - */ - static public BufferedReader getReader(File file, String encoding) throws IOException { - FileInputStream inf = new FileInputStream(file); - InputStreamReader in = new InputStreamReader(inf, encoding); -// FileReader in = new FileReader(file); - BufferedReader result = new BufferedReader(in); - return result; - } - - /** - * Retourne un Writer utilisant l'encoding par defaut {@link #ENCODING} - * - * @param file - * @return - * @throws IOException - */ - static public BufferedWriter getWriter(File file) throws IOException { - return getWriter(file, ENCODING); - } - - /** - * Retourne un writer utilisant l'encoding choisi et plac� dans un - * BufferedWriter - * - * @param file - * @param encoding (ISO-8859-1, UTF-8, ...) - * @return - * @throws IOException - */ - static public BufferedWriter getWriter(File file, String encoding) throws IOException { - FileOutputStream outf = new FileOutputStream(file); - OutputStreamWriter out = new OutputStreamWriter(outf, encoding); -// FileWriter out = new FileWriter(file); - BufferedWriter result = new BufferedWriter(out); - return result; - } - - public static void main(String[] args) { - - } - - /** - * Permet de creer un nouveu repertoire temporaire, l'effacement du - * r�pertoire est a la charge de l'appelant - * @param prefix le prefix du fichier - * @param suffix le suffix du fichier - * @param tmpdir le r�pertoire temporaire ou il faut creer le repertoire - * si null on utilise java.io.tmpdir - * @return le fichier pointant sur le nouveau repertoire - * @throws java.io.IOException - */ - static public File createTempDirectory(String prefix, String suffix, File tmpdir) throws IOException { - if (tmpdir == null) { - tmpdir = new File(System.getProperty("java.io.tmpdir")); - } - File result = new File(tmpdir, prefix + System.currentTimeMillis() + suffix); - while (result.exists()) { - result = new File(tmpdir, prefix + System.currentTimeMillis() + suffix); - } - if (!result.mkdirs()) { - throw new IOException("Can't create temporary directory: " + result); - } - return result; - } - /** - * Permet de creer un nouveu repertoire temporaire, l'effacement du - * r�pertoire est a la charge de l'appelant - * @param prefix - * @param suffix - * @return - * @throws java.io.IOException - */ - static public File createTempDirectory(String prefix, String suffix) throws IOException { - return createTempDirectory(prefix, suffix, null); - } - - /** - * Regarde si le fichier f1 est plus recent que le fichier f2 - * @param f1 - * @param f2 - * @return vrai si f1 est plus recent que f2 - */ - static public boolean isNewer(File f1, File f2) { - boolean result = f1.lastModified() > f2.lastModified(); - return result; - } - - /** - * Permet de lire un fichier et de retourner sont contenu sous forme d'une - * chaine de carateres - * @param file le fichier a lire - * @throws IOException - * @return - */ - static public String readAsString(File file) throws IOException { - StringBuffer result = new StringBuffer(); - char [] cbuf = new char[2000]; - BufferedReader in = getReader(file); - int nb = in.read(cbuf); - while (nb != -1) { - result.append(cbuf, 0, nb); - nb = in.read(cbuf); - } - in.close(); - return result.toString(); - } - - /** - * Permet de sauver une chaine directement dans un fichier - * @param file Le fichier dans lequel il faut ecrire la chaine - * @param content Le texte a ecrire dans le fichier - * @throws IOException if any pb while writing - */ - static public void writeString(File file, String content) throws IOException { - file.getParentFile().mkdirs(); - BufferedWriter out = getWriter(file); - out.write(content); - out.close(); - } - - /** - * Permet de sauver une chaine directement dans un fichier - * @param file Le fichier dans lequel il faut ecrire la chaine - * @param content Le texte a ecrire dans le fichier - * @param encoding encoding to use - * @throws IOException if any pb while writing - */ - static public void writeString(File file, String content,String encoding) throws IOException { - file.getParentFile().mkdirs(); - BufferedWriter out = getWriter(file,encoding); - out.write(content); - out.close(); - } - - /** - * Permet de donner une representation fichier pour une chaine de caractere. - * Le fichier sera automatiquement effac� � la fin de la JVM. - * @param content le contenu du fichier temporaire - * @return le fichier qui contient content - * @throws IOException - */ - static public File getTempFile(String content) throws IOException { - return getTempFile(content, ""); - } - - /** - * Permet de donner une representation fichier pour une chaine de caractere. - * Le fichier sera automatiquement effac� � la fin de la JVM. - * @param content le contenu du fichier temporaire - * @param fileSuffix l'extension du fichier cr�� - * @return le fichier qui contient content - * @throws IOException - */ - static public File getTempFile(String content, String fileSuffix) throws IOException { - File result = File.createTempFile("tmp-" + FileUtil.class.getName(), fileSuffix); - result.deleteOnExit(); - writeString(result, content); - return result; - } - - /** - * Equivalent de la methode basename unix. - * basename("/tmp/toto.xml", ".xml") -> "toto" - * - * @param file le fichier dont on souhaite le nom sans le chemin - * @param suffixes si present represente le suffixe a eliminer du fichier - * s'il est trouv� - * @return le nom du fichier sans le suffixe si trouv�. - */ - static public String basename(File file, String ... suffixes) { - String result = file.getName(); - for(String suffixe : suffixes) { - if (result.endsWith(suffixe)){ - result = result.substring(0, result.length() - suffixe.length()); - break; - } - } - return result; - } - - /** - * Permet de r�cup�rer l'extension d'un fichier - * @param file le fichier dont on souhaite l'extension - * @param extchars la liste des caracteres pouvant former l'extension - * dans l'ordre de preference. Si vide on utilise ".". - * @return l'extension ou la chaine vide si le fichier n'a pas d'extension - * l'extension ne contient pas le chaine de delimitation - */ - static public String extension(File file, String ... extchars) { - String result = ""; - String name = file.getName(); - - if(extchars.length == 0) { - extchars = new String[]{"."}; - } - for (String extchar : extchars) { - int pos = name.lastIndexOf(extchar); - if (pos != -1) { - result = name.substring(pos + extchar.length()); - break; - } - } - return result; - } - - static public interface FileAction { - public boolean doAction(File f); - } - - /** - * Retourne tous les sous r�pertoires du r�pertoire pass� en argument. - * @param directory un r�pertoire - * @return une liste d'objet {@link java.io.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> getSubDirectories(File directory) { - class DirectoryFilter implements FileFilter { - public boolean accept(File f) { - return f.isDirectory(); - } - } - return getFilteredElements(directory, new DirectoryFilter(), true); - } - - /** - * Retourne tous les fichiers du r�pertoire pass� en argument. - * @param directory un r�pertoire - * @return une liste d'objet {@link java.io.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> getFiles(File directory) { - class NormalFileFilter implements FileFilter { - public boolean accept(File f) { - return f.isFile(); - } - } - return getFilteredElements(directory, new NormalFileFilter(), true); - } - - /** - * Retourne les fichiers d'un r�pertoire qui s'attisfont un certain pattern. - * La recherche est faite r�cursivement dans les sous r�pertoires - * @param directory le r�pertoire � partir duquel il faut faire la recherche - * @param pattern le pattern que doit respecter le fichier pour �tre dans la - * liste r�sultante - * @param recursively - * @return une liste d'objet {@link java.io.File} qui ont s'attisfait le - * pattern. - */ - public static List<File> find(File directory, final String pattern, boolean recursively){ - final String root = directory.getAbsolutePath(); - final int rootLength = root.length(); - - return getFilteredElements(directory, new FileFilter() { - public boolean accept(File f) { - String longFilename = f.getAbsolutePath(); - // + 1 to remove the first / or \ - String filename = longFilename.substring(rootLength + 1); - return filename.matches(pattern); - } - }, recursively); - } - - /** - * Retourne la liste de toutes les fichiers ou r�pertoire qui s'attisfont - * le filtre - * @param directory repertoire � partir duquel il faut faire la recherche - * @param ff le filtre � appliquer pour savoir si le fichier parcouru doit - * �tre conserv� dans les r�sultats, ou null pour tous les fichiers - * @param recursively - * @return une liste d'objet {@link java.io.File}, qui s'attisfont le filtre - */ - public static List<File> getFilteredElements(File directory, FileFilter ff, boolean recursively) { - ArrayList<File> result = new ArrayList<File>(); - LinkedList<File> todo = new LinkedList<File>(); - if (directory.isDirectory()){ - todo.addAll(Arrays.asList(directory.listFiles())); - } - while(todo.size() > 0){ - File file = todo.removeFirst(); - if (recursively && file.isDirectory()){ - File [] childs = file.listFiles(); - if (childs != null) { // null if we don't have access to directory - todo.addAll(Arrays.asList(childs)); - } - } - if(ff == null || ff.accept(file)){ - result.add(file); - } - } - return result; - } - - /** - * Supprime recursivement tout le contenu d'un r�pertoire. - * @param directory - * @return vrai si tout se passe bien, false si la suppression d'un �lement - * se passe mal - */ - public static boolean deleteRecursively(String directory) { - return deleteRecursively(new File(directory)); - } - - /** - * Supprime recursivement tout le contenu d'un r�pertoire. - * @param directory - * @return vrai si tout se passe bien, false si la suppression d'un �lement - * se passe mal - */ - public static boolean deleteRecursively(File directory) { - return walkBefore(directory, new FileAction(){ - public boolean doAction(File f) { - return f.delete(); - } - }); - } - - /** - * 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. - * @param f le fichier ou r�pertoire � partir duquel il faut commencer - * @param fileAction l'action � effectuer sur chaque fichier - * @return le r�sultat des fileAction execut� sur les fichiers, chaque - * r�sultat de FileAction sont assembl� par un ET logique pour donner - * le r�sultat final - */ - public static boolean walkAfter(File f, FileAction fileAction) { - boolean result=fileAction.doAction(f); - if (f.isDirectory()) { - File list[] = f.listFiles(); - for (int i = 0; i < list.length; i++) { - result=result && walkAfter(list[i], fileAction); - } - } - return result; - } - - /** - * 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. - * @param f le fichier ou r�pertoire � partir duquel il faut commencer - * @param fileAction l'action � effectuer sur chaque fichier - * @return le r�sultat des fileAction execut� sur les fichiers, chaque - * r�sultat de FileAction sont assembl� par un ET logique pour donner - * le r�sultat final - */ - public static boolean walkBefore(File f, FileAction fileAction) { - boolean result=true; - if (f.isDirectory()) { - File list[] = f.listFiles(); - for (int i = 0; i < list.length; i++) { - result=result && walkBefore(list[i], fileAction); - } - } - return result && fileAction.doAction(f); - } - - /** - * Permet de copier le fichier source vers le fichier cible. - * @param source le fichier source - * @param target le fichier cible - * @throws IOException Erreur de copie - */ - public static void copy(File source, File target) throws IOException { - target.getParentFile().mkdirs(); - FileChannel sourceChannel = new FileInputStream(source).getChannel(); - FileChannel targetChannel = new FileOutputStream(target).getChannel(); - sourceChannel.transferTo(0, sourceChannel.size(), targetChannel); - // or - // targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); - sourceChannel.close(); - targetChannel.close(); - } - - /** - * Permet de copier le fichier source vers le fichier cible. - * @param source le fichier source - * @param target le fichier cible - * @throws IOException Erreur de copie - */ - public static void copy(String source, String target) throws IOException { - copy(new File(source), new File(target)); - } - - /** - * Copie recursivement le repertoire source dans le repertoire destination - * - * copyRecursively("/truc/titi", "/var/tmp") donnera le repertoire - * "/var/tmp/titi" - * - * @param srcDir - * @param destDir - * @param includePatterns les patterns que doivent resperter les - * fichiers/repertoires pour etre copi�. Si vide alors tout est copi� - * - * @throws IOException - */ - static public void copyRecursively(File srcDir, File destDir, String ... includePatterns) throws IOException { - copyAndRenameRecursively(srcDir, destDir, null, null, 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' - * - * @param srcDir - * @param destDir - * @param renameFrom pattern to permit rename file before uncompress it - * @param renameTo new name for file if renameFrom is applicable to it - * you can use $1, $2, ... if you have '(' ')' in renameFrom - * @param includePatterns les patterns que doivent resperter les - * fichiers/repertoires pour etre copi�. Si vide alors tout est copi� - * - * @throws IOException - */ - static public void copyAndRenameRecursively(File srcDir, File destDir, - String renameFrom, String renameTo, String ... includePatterns) throws IOException { - copyAndRenameRecursively(srcDir, destDir, true, renameFrom, renameTo, false, 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' - * - * @param srcDir - * @param destDir - * @param includeSrcDir si vrai alors le repertoire source est copie dans le - * repertoire destination et non pas seulement les fichiers qu'il contient - * @param renameFrom pattern to permit rename file before uncompress it - * @param renameTo new name for file if renameFrom is applicable to it - * you can use $1, $2, ... if you have '(' ')' in renameFrom - * @param exclude inverse include pattern interpretation - * @param includePatterns les patterns que doivent resperter les - * fichiers/repertoires pour etre copi�. Si vide alors tout est copi� - * - * @throws IOException - */ - static public void copyAndRenameRecursively(File srcDir, File destDir, - boolean includeSrcDir, String renameFrom, String renameTo, boolean exclude, - String ... includePatterns) throws IOException { - String rootSrc; - if (includeSrcDir) { - rootSrc = srcDir.getParent(); - } else { - rootSrc = srcDir.getPath(); - } - List<File> files = getFilteredElements(srcDir, null, true); - log.debug("copyRecursively: " + files); - for (File file : files) { - boolean doCopy = copyRecursivelyAccept(file, includePatterns); - if (xor(exclude, doCopy)) { - String path = file.getPath().substring(rootSrc.length()); - if (renameFrom != null && renameTo != null) { - String tmp = path.replaceAll(renameFrom, renameTo); - if (log.isDebugEnabled()) { - log.debug("rename " + path + " -> " + tmp); - } - path = tmp; - } - - File destFile = new File(destDir, path); - if (file.isDirectory()) { - log.debug("create directory: " + destFile); - destFile.mkdirs(); - } else { - log.debug("copy " + path + " to " + destFile); - copy(file, destFile); - } - } - } - } - - static private boolean xor(boolean b, boolean c) { - if (b) return !c; - else return c; - } - - /** - * @param file - * @param includePatterns - * @return - */ - private static boolean copyRecursivelyAccept(File file, String[] includePatterns) { - boolean result = includePatterns.length == 0; - String filename = file.getAbsolutePath(); - for (String pattern : includePatterns) { - result = filename.matches(pattern); - if (result) { - break; - } - } - return result; - } - -} // FileUtil - Deleted: trunk/lutinutil/src/main/java/org/codelutin/util/PropertiesDateRemoveFilterStream.java =================================================================== --- trunk/lutinutil/src/main/java/org/codelutin/util/PropertiesDateRemoveFilterStream.java 2008-07-31 20:12:39 UTC (rev 951) +++ trunk/lutinutil/src/main/java/org/codelutin/util/PropertiesDateRemoveFilterStream.java 2008-07-31 20:35:40 UTC (rev 952) @@ -1,50 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package org.codelutin.util; - -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -public class PropertiesDateRemoveFilterStream extends FilterOutputStream { - - private boolean firstLineOver; - char endChar; - - public PropertiesDateRemoveFilterStream(OutputStream out) { - super(out); - firstLineOver = false; - String lineSeparator = java.security.AccessController - .doPrivileged(new sun.security.action.GetPropertyAction( - "line.separator")); - endChar = lineSeparator.charAt(lineSeparator.length() - 1); - } - - @Override - public void write(int b) throws IOException { - if (!firstLineOver) { - char c = (char) b; - if (c == endChar) { - firstLineOver = true; - } - } else { - out.write(b); - } - } - -} \ No newline at end of file Deleted: trunk/lutinutil/src/main/java/org/codelutin/util/SortedProperties.java =================================================================== --- trunk/lutinutil/src/main/java/org/codelutin/util/SortedProperties.java 2008-07-31 20:12:39 UTC (rev 951) +++ trunk/lutinutil/src/main/java/org/codelutin/util/SortedProperties.java 2008-07-31 20:35:40 UTC (rev 952) @@ -1,62 +0,0 @@ -/* *##% - * Copyright (C) 2007 - * I18nPlugin, Code Lutin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -package org.codelutin.util; - -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; -import java.util.Properties; -import java.util.Vector; - -/** - * Permet d'avoir les fichiers de propri�t�s tri�s. - * - * @author julien - */ -public class SortedProperties extends Properties { - - private static final long serialVersionUID = -1147150444452577558L; - - - public SortedProperties() { - super(); - } - - public SortedProperties(Properties defaults) { - super(defaults); - } - - @Override - public synchronized Enumeration<Object> keys() { - List<Object> objects = Collections.list(super.keys()); - Vector<Object> result; - try { - // Attention, si les clef ne sont pas des string, ca ne marchera pas - List<String> list = CollectionUtil.toGenericList(objects, String.class); - Collections.sort(list); - result = new Vector<Object>(list); - } catch (IllegalArgumentException e) { - // keys are not string !!! - // can not sort keys - result = new Vector<Object>(objects); - } - return result.elements(); - } -} Deleted: trunk/lutinutil/src/main/java/org/codelutin/util/StringUtil.java =================================================================== --- trunk/lutinutil/src/main/java/org/codelutin/util/StringUtil.java 2008-07-31 20:12:39 UTC (rev 951) +++ trunk/lutinutil/src/main/java/org/codelutin/util/StringUtil.java 2008-07-31 20:35:40 UTC (rev 952) @@ -1,552 +0,0 @@ -/* *##%% - * Copyright (C) 2002, 2003 Code Lutin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%%**/ -/* * - * StringUtil.java - * - * Created: Sun Apr 14 2002 - * - * @author POUSSIN Benjamin <bpoussin@free.fr> - * Copyright Code Lutin - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -package org.codelutin.util; - -import java.awt.Color; -import java.lang.reflect.Field; -import java.text.DateFormat; -import java.text.MessageFormat; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -/** - * Classe contenant un ensemle de methode static utiles pour la manipulation des - * chaine de caractere mais qui ne sont pas defini dans la classe String de - * Java. - * - * @author poussin - * @created 21 octobre 2003 - */ -public class StringUtil { // StringUtil - - /** Constructor for the StringUtil object */ - protected StringUtil() { - } - - /** - * Cette methode retire les accents. Quand le caractere est connu, elle le - * remplace par une version sans accent sinon, elle le supprime. - * Les caracteres non-alphanumeriques sont supprimes. - * - * @param s la chaine a unaccentuer - * @return la chaine sans accent - */ - static public String unaccent(String s) { - String result = ""; - for (char c : s.toCharArray()) { - if ("����".indexOf(c) != -1) { - result += "e"; - } else if ("���".indexOf(c) != -1) { - result += "a"; - } else if ("�".indexOf(c) != -1) { - result += "c"; - } else if ("��".indexOf(c) != -1) { - result += "i"; - } else if ("��".indexOf(c) != -1) { - result += "o"; - } else if ("���".indexOf(c) != -1) { - result += "u"; - } else if ("����".indexOf(c) != -1) { - result += "E"; - } else if ("���".indexOf(c) != -1) { - result += "A"; - } else if ("�".indexOf(c) != -1) { - result += "C"; - } else if ("��".indexOf(c) != -1) { - result += "I"; - } else if ("��".indexOf(c) != -1) { - result += "O"; - } else if ("���".indexOf(c) != -1) { - result += "U"; - } else if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') - || ('0' <= c && c <= '9') || ('.' == c) || ('-' == c) - || ('_' == c)) { - result += c; - } else { - // on ne l'ajoute pas a result donc on supprime le caractere - // result += encodeUTF(c); - } - } - return result; - } - - static public String substring(String s, int begin) { - String result; - result = substring(s, begin, s.length()); - return result; - } - - static public String substring(String s, int begin, int end) { - if (begin < 0) { - begin = s.length() + begin; - } - if (end < 0) { - end = s.length() + end; - } - if (end < begin) { - end = begin; - } - - String result; - result = s.substring(begin, end); - return result; - } - - /** - * Met en majuscule le premier caractere de la chaine passee en parametre - * - * @param word La chaine a capitaliser - * @return La chaine capitalisee - * @deprecated you must use - * org.apache.commons.lang.StringUtils.capitalise(String) - */ - public static String capitalize(String word) { - return word.substring(0, 1).toUpperCase() + word.substring(1); - } - - /** - * Met en minuscule le premier caractere de la chaine passe en parametre - * - * @param word La chaine a decapitaliser - * @return La chaine decapitalisee - * @deprecated you must use - * org.apache.commons.lang.StringUtils.uncapitalise(String) - */ - public static String uncapitalize(String word) { - return word.substring(0, 1).toLowerCase() + word.substring(1); - } - - /** - * Concat�ne un tableau de chaine de caracteres en une seul chaine. - * - * @param s le tableau de chaines - * @param sep le separateur a utiliser pour separer chaque chaine. - * @return la chaine resultante de la concatenation. Si le tableau est null - * ou vide, la chaine resultante est une chaine vide. - * @deprecated you must use org.apache.commons.lang.StringUtils.join - */ - public static String unsplit(String[] s, String sep) { - if (s == null || s.length <= 0) { - return ""; - } - - StringBuffer result = new StringBuffer(s[0]); - for (int i = 1; i < s.length; i++) { - result.append(sep).append(s[i]); - } - return result.toString(); - } - - private static final Character[] openingChars = {'(', '{', '['}; - - private static final Character[] closingChars = {')', '}', ']'}; - - /** - * Split string use 'separator' as separator. If String contains "'()[]{} - * this method count the number of open char end close char to split - * correctly argument - * - * @param args string to split - * @param separator separator use to split string - * @return array of string - */ - static public String[] split(String args, String separator) { - return split(openingChars, closingChars, args, separator); - } - - - /** - * Use to split string array representation in array according with swixat - * seperator list - * - * @param stringList string that represent array - * @return array with length > 0 if listAsString != null or null - */ - static public String[] split(String stringList) { - String[] result; - result = split(stringList, ","); - return result; - } - - /** - * Split string use 'separator' as separator. If String contains "' - * and <code>openingChar</code> <code>closingChars</code> - * <p/> - * this method count the number of open char end close char to split correctly - * argument - * - * @param openingChars list of opening caracteres - * @param closingChars list of closing caracteres - * @param args string to split - * @param separator separator use to split string - * @return array of string - */ - static public String[] split(Character[] openingChars, - Character[] closingChars, - String args, String separator) { - if (args == null) { - return new String[0]; - } - - List<String> result = new ArrayList<String>(); - - int start = 0; - int end; - StringBuffer op = new StringBuffer(); // stack of {([< currently open - char last = '\0'; // contains " or ' if string is openned - - List<Character> opening = Arrays.asList(openingChars); - - List<Character> closing = Arrays.asList(closingChars); - - for (int i = 0; i < args.length(); i++) { - char c = args.charAt(i); - if (c == '\\') { - // pass next char - i++; - } else if (last != '"' && last != '\'') { - if (opening.contains(c)) { - op.append(c); - } else if (closing.contains(c)) { - op.deleteCharAt(op.length() - 1); - } else if (c == '"' || c == '\'') { - // open string " or ' - last = c; - } else if (op.length() == 0 && - args.regionMatches(i, separator, 0, separator.length())) { - // end of one arguement - end = i; - // pass separator - i += separator.length() - 1; - - String a = args.substring(start, end); - result.add(a); - // start of next argument - start = end + separator.length(); - } - } else if (c == last) { - // close string " or ' - last = '\0'; - } - } - - if (start < args.length()) { - String a = args.substring(start, args.length()); - result.add(a); - } - - return result.toArray(new String[result.size()]); - } - - public static boolean toBoolean(String s) { - return "true".equalsIgnoreCase(s); - } - - public static byte toByte(String s) { - return Byte.parseByte(s); - } - - public static double toDouble(String s) { - return Double.parseDouble(s); - } - - public static float toFloat(String s) { - return Float.parseFloat(s); - } - - public static long toLong(String s) { - return Long.parseLong(s); - } - - public static short toShort(String s) { - return Short.parseShort(s); - } - - public static int toInt(String s) { - return Integer.parseInt(s); - } - - public static char toChar(String s) { - // fixme a revoir - return s.charAt(0); - } - - public static boolean[] toArrayBoolean(String... s) { - boolean[] result = new boolean[s.length]; - for (int i = 0; i < result.length; i++) { - result[i] = toBoolean(s[i]); - } - return result; - } - - public static byte[] toArrayByte(String... s) { - byte[] result = new byte[s.length]; - for (int i = 0; i < result.length; i++) { - result[i] = toByte(s[i]); - } - return result; - } - - public static double[] toArrayDouble(String... s) { - double[] result = new double[s.length]; - for (int i = 0; i < result.length; i++) { - result[i] = toDouble(s[i]); - } - return result; - } - - public static float[] toArrayFloat(String... s) { - float[] result = new float[s.length]; - for (int i = 0; i < result.length; i++) { - result[i] = toFloat(s[i]); - } - return result; - } - - public static long[] toArrayLong(String... s) { - long[] result = new long[s.length]; - for (int i = 0; i < result.length; i++) { - result[i] = toLong(s[i]); - } - return result; - } - - public static short[] toArrayShort(String... s) { - short[] result = new short[s.length]; - for (int i = 0; i < result.length; i++) { - result[i] = toShort(s[i]); - } - return result; - } - - public static int[] toArrayInt(String... s) { - int[] result = new int[s.length]; - for (int i = 0; i < result.length; i++) { - result[i] = toInt(s[i]); - } - return result; - } - - public static char[] toArrayChar(String... s) { - char[] result = new char[s.length]; - for (int i = 0; i < result.length; i++) { - result[i] = toChar(s[i]); - } - // fixme a revoir - return result; - } - - /** - * Essai de convertir une chaine de caractere en une couleur si possible si - * ce n'est pas possible retourne null. - * - * @param s la couleur sous la forme de string, par exemple "red", - * "yellow" ou bien en RGB "#FFAA99", et avec un canal alpha - * "#FFAA3366" - * @return la couleur demand� si possible sinon null - * @throws IllegalArgumentException - * @throws StringUtilException if any problem while conversion - */ - public static Color toColor(String s) throws StringUtilException { - try { - if (s.startsWith("#")) { - // r�cuperation des valeurs hexa - String hr = s.substring(1, 3); - String hg = s.substring(3, 5); - String hb = s.substring(5, 7); - - // conversion en entier - int r = Integer.parseInt(hr, 16); - int g = Integer.parseInt(hg, 16); - int b = Integer.parseInt(hb, 16); - - if (s.length() == 9) { - // s'il y a un canal alpha on l'utilise - String ha = s.substring(7, 9); - int a = Integer.parseInt(ha, 16); - return new Color(r, g, b, a); - } else { - return new Color(r, g, b); - } - } else { - Field f; - f = Color.class.getField(s); - return (Color) f.get(Color.class); - } - } catch (NumberFormatException e) { - throw new StringUtilException( - "Error during conversion from string to color", e); - } catch (SecurityException e) { - throw new StringUtilException( - "Error during conversion from string to color", e); - } catch (NoSuchFieldException e) { - throw new StringUtilException( - "Error during conversion from string to color", e); - } catch (IllegalArgumentException e) { - throw new StringUtilException( - "Error during conversion from string to color", e); - } catch (IllegalAccessException e) { - throw new StringUtilException( - "Error during conversion from string to color", e); - } - } - - public static Date toDate(String s) throws ParseException { - return DateFormat.getDateInstance().parse(s); - } - - static final protected double[] timeFactors = {1000000, 1000, 60, 60, 24}; - - static final protected String[] timeUnites = {"ns", "ms", "s", "m", "h", - "d"}; - - static public String convertTime(long value) { - return convert(value, timeFactors, timeUnites); - } - - static public String convertTime(long value,long value2) { - return convertTime(value2-value); - } - - static final protected double[] memoryFactors = {1024, 1024, 1024, 1024}; - - static final protected String[] memoryUnites = {"o", "Ko", "Mo", "Go", - "To"}; - - static public String convertMemory(long value) { - return convert(value, memoryFactors, memoryUnites); - } - - static public String convert(long value, double[] factors, String[] unites) { - long sign = value == 0 ? 1 : value / Math.abs(value); - int i = 0; - double tmp = Math.abs(value); - while (i < factors.length && i < unites.length && tmp > factors[i]) { - tmp = tmp / factors[i++]; - } - - tmp *= sign; - String result; - result = MessageFormat.format("{0,number,0.###}{1}", tmp, - unites[i]); - return result; - } - - /** - * V�rifie q'une chaine de caract�re est valid pour les bloc openner closer, ie. - * <p/> - * que les blocs d�finit par les deux caract�res s'entrechevauchent pas. - * <p/> - * Exemple avec '(' ')' : - * <p/> - * (a(b)) est valide, par contre ((aaa))) n'est pas valide - * - * @param txt txte a verifier - * @param opener le caract�re ouvrant - * @param closer le caract�re fermant - * @return <code>true</code> is la chaine est valide - */ - public static boolean checkEnclosure(String txt, final char opener, char closer) { - if (txt.indexOf(opener) == -1 && txt.indexOf(closer) == -1) { - // ok pas de block d�tect�s - return true; - } - List<Integer> opens = new ArrayList<Integer>(); - for (int i = 0; i < txt.length(); i++) { - char c = txt.charAt(i); - if (c == opener) { - // add a open block - opens.add(i); - continue; - } - if (c == closer) { - if (opens.isEmpty()) { - // problem no block left - return false; - } - // on supprime le dernier bloc - opens.remove(opens.size() - 1); - } - } - return opens.isEmpty(); - } - - /** - * Convertir un nom en une constante Java - * - * Les seuls caract�res autoris�s sont les alpha num�riques, ains - * que l'underscore. tous les autres caract�res seront ignor�s. - * - * @param name le nom � convertir - * @return la constante g�n�r�e - */ - public static String convertToConstantName(String name) { - StringBuilder sb = new StringBuilder(); - char lastChar=0; - for (int i = 0, j = name.length(); i < j; i++) { - char c = name.charAt(i); - if (Character.isDigit(c)) { - sb.append(c); - lastChar = c; - continue; - } - if (!Character.isLetter(c)) { - if (lastChar != '_') { - sb.append('_'); - } - lastChar='_'; - continue; - } - if (Character.isUpperCase(c)) { - if (!Character.isUpperCase(lastChar)&&lastChar!='_') { - sb.append('_'); - } - sb.append(c); - } else { - sb.append(Character.toUpperCase(c)); - } - lastChar=c; - } - String result = sb.toString(); - // clean tail - while (!result.isEmpty() && result.endsWith("_")) { - result = result.substring(0,result.length()-1); - } - // clean head - while (!result.isEmpty() && result.startsWith("_")) { - result = result.substring(1); - } - return result; - } - -} Deleted: trunk/lutinutil/src/main/java/org/codelutin/util/StringUtilException.java =================================================================== --- trunk/lutinutil/src/main/java/org/codelutin/util/StringUtilException.java 2008-07-31 20:12:39 UTC (rev 951) +++ trunk/lutinutil/src/main/java/org/codelutin/util/StringUtilException.java 2008-07-31 20:35:40 UTC (rev 952) @@ -1,24 +0,0 @@ -/* - * Created on Dec 7, 2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.codelutin.util; - -/** - * @author pineau - * - * TODO To change the template for this generated type comment go to - * Window - Preferences - Java - Code Style - Code Templates - */ -public class StringUtilException extends RuntimeException { - - /** */ - private static final long serialVersionUID = 6148795384335489591L; - - public StringUtilException(String message, Exception e) { - super(message, e); - } - -} Copied: trunk/lutinutil-io/src/main/java/org/codelutin/util/CollectionUtil.java (from rev 949, trunk/lutinutil/src/main/java/org/codelutin/util/CollectionUtil.java) =================================================================== --- trunk/lutinutil-io/src/main/java/org/codelutin/util/CollectionUtil.java (rev 0) +++ trunk/lutinutil-io/src/main/java/org/codelutin/util/CollectionUtil.java 2008-07-31 20:35:40 UTC (rev 952) @@ -0,0 +1,156 @@ +/* *##% + * Copyright (C) 2006 + * Code Lutin, C�dric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * CollectionUtil.java + * + * Created: 23 f�vr. 2006 09:03:39 + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ + +package org.codelutin.util; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; + + +/** + * @author poussin + * + */ + +public class CollectionUtil { + + /** + * Ajoute a la collection tous les elements pass�s en parametre + * @param col la collection + * @param e les elements a ajouter + * @return la collection pass� en parametre + */ + static public <A, E extends Collection<A>> E addAll(E col, A ... e) { + Collections.addAll(col, e); + return col; + } + + /** + * Ajoute a la liste tous les elements pass�s en parametre + * @param col la liste + * @param pos le premier index o� ins�rer les donn�es + * @param e les elements a ajouter + * @return la liste pass� en parametre + */ + static public <A, E extends List<A>> E addAll(E col, int pos, A ... e) { + col.addAll(pos, Arrays.asList(e)); + return col; + } + + /** + * Permet de convertir une liste non typ�e, en une liste typ�e. + * + * La liste en entr�e en juste bien cast�e. + * + * On effectue une v�rification sur le typage des �lements de la liste. + * + * Note : <b>Aucune liste n'est cr�ee, ni recopi�e</b> + * + * @param list la liste � convertir + * @param type le type des �l�ments de la liste + * @return la liste typ�e + * @throws IllegalArgumentException si un �l�ment de la liste en entr�e n'est + * pas en ad�quation avec le type voulue. + */ + @SuppressWarnings({"unchecked"}) + static public <O> List<O> toGenericList(List list,Class<O> type) throws IllegalArgumentException { + if (list.isEmpty()) { + return list; + } + for (Object o : list) { + if (!(type.isAssignableFrom(o.getClass()))) { + throw new IllegalArgumentException("can not cast List with object of type "+o.getClass()+" to "+type+" type!"); + } + } + return list; + } + + /** + * Permet de convertir une collection non typ�e, en une collection typ�e. + * + * La collection en entr�e en juste bien cast�e. + * + * On effectue une v�rification sur le typage des �lements de la collection. + * + * Note : <b>Aucune collection n'est cr�ee, ni recopi�e</b> + * + * @param list la collection � convertir + * @param type le type des �l�ments de la collection + * @return la collection typ�e + * @throws IllegalArgumentException si un �l�ment de la collection en entr�e n'est + * pas en ad�quation avec le type voulue. + */ + @SuppressWarnings({"unchecked"}) + static public <O> Collection<O> toGenericCollection(Collection list,Class<O> type) throws IllegalArgumentException { + if (list.isEmpty()) { + return list; + } + for (Object o : list) { + if (!(type.isAssignableFrom(o.getClass()))) { + throw new IllegalArgumentException("can not cast Collection with object of type "+o.getClass()+" to "+type+" type!"); + } + } + return list; + } + + /** + * Permet de convertir un ensemble non typ�e, en un ensemble typ�e. + * + * L'ensemble en entr�e en juste bien cast�e. + * + * On effectue une v�rification sur le typage des �lements de la collection. + * + * Note : <b>Aucun ensemble n'est cr�ee, ni recopi�e</b> + * + * @param list l'ensemble � convertir + * @param type le type des �l�ments de l'ensemble + * @return l'ensemble typ�e + * @throws IllegalArgumentException si un �l�ment de l'ensemble en entr�e n'est + * pas en ad�quation avec le type voulue. + */ + @SuppressWarnings({"unchecked"}) + static public <O> Set<O> toGenericSet(Set list,Class<O> type) throws IllegalArgumentException { + if (list.isEmpty()) { + return list; + } + for (Object o : list) { + if (!(type.isAssignableFrom(o.getClass()))) { + throw new IllegalArgumentException("can not cast Set with object of type "+o.getClass()+" to "+type+" type!"); + } + } + return list; + } +} + + Property changes on: trunk/lutinutil-io/src/main/java/org/codelutin/util/CollectionUtil.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: trunk/lutinutil-io/src/main/java/org/codelutin/util/FileUtil.java (from rev 949, trunk/lutinutil/src/main/java/org/codelutin/util/FileUtil.java) =================================================================== --- trunk/lutinutil-io/src/main/java/org/codelutin/util/FileUtil.java (rev 0) +++ trunk/lutinutil-io/src/main/java/org/codelutin/util/FileUtil.java 2008-07-31 20:35:40 UTC (rev 952) @@ -0,0 +1,766 @@ +/* *##% + * Copyright (C) 2002, 2003, 2004 Code Lutin, C�dric Pineau, + * Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +/* * + * FileUtil.java + * + * Created: 22 nov. 2004 + * + * @author Benjamin Poussin <poussin@codelutin.com> + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ + +package org.codelutin.util; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import javax.swing.JFileChooser; + +import org.apache.commons.logging.LogFactory; + +public class FileUtil { // FileUtil + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private org.apache.commons.logging.Log log = LogFactory.getLog(FileUtil.class); + + /** Encoding par defaut utilis� si non sp�cifi� */ + static public String ENCODING = "ISO-8859-1"; + static protected File currentDirectory = new File("."); + + static public void setCurrentDirectory(File dir){ + currentDirectory = dir; + } + + static public class PatternChooserFilter extends javax.swing.filechooser.FileFilter { + protected String pattern = null; + protected String description = null; + + public PatternChooserFilter(String pattern, String description) { + this.pattern = pattern; + this.description = description; + } + + @Override + public boolean accept(File f) { + return f.isDirectory() || f.getAbsolutePath().matches(pattern); + } + @Override + public String getDescription() { + return description; + } + + } + + + /** + * Retourne le nom du fichier entre dans la boite de dialogue. + * Si le bouton annuler est utilis�, ou qu'il y a une erreur retourne null. + * + * @param patternOrDescriptionFilters les filtres a utiliser, les chaines doivent etre donn�es + * par deux, le pattern du filtre + la description du filtre + * @return + * + * @see #getFile(javax.swing.filechooser.FileFilter[]) + */ + static public File getFile(String ... patternOrDescriptionFilters) { + if (patternOrDescriptionFilters.length % 2 != 0) { + throw new IllegalArgumentException("Arguments must be (pattern, description) couple"); + } + javax.swing.filechooser.FileFilter [] filters = new javax.swing.filechooser.FileFilter[patternOrDescriptionFilters.length / 2]; + for (int i=0; i<filters.length; i++) { + String pattern = patternOrDescriptionFilters[i*2]; + String description = patternOrDescriptionFilters[i*2 + 1]; + filters[i] = new PatternChooserFilter(pattern, description); + } + File result; + result = getFile(filters); + return result; + } + + /** + * Retourne le nom du fichier entre dans la boite de dialogue. + * Si le bouton annuler est utilis�, ou qu'il y a une erreur retourne null. + * + * @param filters les filtres a ajouter + * @return + */ + static public File getFile(javax.swing.filechooser.FileFilter ... filters){ + try{ + JFileChooser chooser = new JFileChooser(currentDirectory); + + chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); + if (filters.length > 0) { + if (filters.length == 1) { + chooser.setFileFilter(filters[0]); + } else { + for (javax.swing.filechooser.FileFilter filter : filters) { + chooser.addChoosableFileFilter(filter); + } + } + } + chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + int returnVal = chooser.showDialog(null, "Ok"); + if(returnVal == JFileChooser.APPROVE_OPTION) { + File theFile = chooser.getSelectedFile(); + if(theFile != null) { + currentDirectory = theFile; + return theFile.getAbsoluteFile(); + } + } + } + catch(Exception eee){ + log.warn("Erreur:", eee); + } + return null; + } + + /** + * @param title le nom de la boite de dialogue + * @param approvalText + * @return le nom du repertoire entre dans la boite de dialogue. + * Si le bouton annuler est utilis�, ou qu'il y a une erreur retourne + * null. + */ + static public String getDirectory(String title,String approvalText) { + try{ + JFileChooser chooser = new JFileChooser(currentDirectory); + chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setDialogTitle(title); + int returnVal = chooser.showDialog(null,approvalText); + if(returnVal == JFileChooser.APPROVE_OPTION) { + File theFile = chooser.getSelectedFile(); + if(theFile != null) { + currentDirectory = theFile; + if(theFile.isDirectory()) { + return theFile.getAbsolutePath(); + } + } + } + else{ + return null; + } + } catch(Exception eee){ + log.warn("Erreur:", eee); + } + return null; + } + + /** + * @return le nom du repertoire entre dans la boite de dialogue. + * Si le bouton annuler est utilis�, ou qu'il y a une erreur retourne + * null. + */ + static public String getDirectory() { + return getDirectory("Ok","Ok"); + } + + /** + * Permet de convertir un fichier en un tableau de byte + * + * @param file + * @return + * @throws IOException + */ + static public byte[] fileToByte(File file) throws IOException { + InputStream in = new BufferedInputStream(new FileInputStream(file)); + ByteArrayOutputStream result = new ByteArrayOutputStream(); + BufferedOutputStream tmp = new BufferedOutputStream(result); + for (int b=in.read(); b != -1; b=in.read()) { + tmp.write(b); + } + in.close(); + tmp.close(); + + return result.toByteArray(); + } + + /** + * Permet de convertir des bytes en fichier, le fichier sera automatiquement + * supprim� a la fin de la JVM. + * + * @param bytes + * @return le fichier temporaire contenant les bytes + * @throws IOException + */ + static public File byteToFile(byte[] bytes) throws IOException { + File file = File.createTempFile("FileUtil-byteToFile", ".tmp"); + byteToFile(bytes, file); + return file; + } + + /** + * Permet de convertir des bytes en fichier + * + * @param bytes + * @param file le fichier dans lequel il faut ecrire les bytes + * @return le fichier pass� en parametre + * @throws IOException + */ + static public File byteToFile(byte[] bytes, File file) throws IOException { + OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); + out.write(bytes); + out.close(); + return file; + } + + /** + * Retourne un Reader utilisant l'encoding par defaut {@link #ENCODING} + * + * @param file + * @return + * @throws IOException + */ + static public BufferedReader getReader(File file) throws IOException { + return getReader(file, ENCODING); + } + + /** + * Retourne un reader utilisant l'encoding choisi et plac� dans un + * BufferedReader + * + * @param file + * @param encoding (ISO-8859-1, UTF-8, ...) + * @return + * @throws IOException + */ + static public BufferedReader getReader(File file, String encoding) throws IOException { + FileInputStream inf = new FileInputStream(file); + InputStreamReader in = new InputStreamReader(inf, encoding); +// FileReader in = new FileReader(file); + BufferedReader result = new BufferedReader(in); + return result; + } + + /** + * Retourne un Writer utilisant l'encoding par defaut {@link #ENCODING} + * + * @param file + * @return + * @throws IOException + */ + static public BufferedWriter getWriter(File file) throws IOException { + return getWriter(file, ENCODING); + } + + /** + * Retourne un writer utilisant l'encoding choisi et plac� dans un + * BufferedWriter + * + * @param file + * @param encoding (ISO-8859-1, UTF-8, ...) + * @return + * @throws IOException + */ + static public BufferedWriter getWriter(File file, String encoding) throws IOException { + FileOutputStream outf = new FileOutputStream(file); + OutputStreamWriter out = new OutputStreamWriter(outf, encoding); +// FileWriter out = new FileWriter(file); + BufferedWriter result = new BufferedWriter(out); + return result; + } + + public static void main(String[] args) { + + } + + /** + * Permet de creer un nouveu repertoire temporaire, l'effacement du + * r�pertoire est a la charge de l'appelant + * @param prefix le prefix du fichier + * @param suffix le suffix du fichier + * @param tmpdir le r�pertoire temporaire ou il faut creer le repertoire + * si null on utilise java.io.tmpdir + * @return le fichier pointant sur le nouveau repertoire + * @throws java.io.IOException + */ + static public File createTempDirectory(String prefix, String suffix, File tmpdir) throws IOException { + if (tmpdir == null) { + tmpdir = new File(System.getProperty("java.io.tmpdir")); + } + File result = new File(tmpdir, prefix + System.currentTimeMillis() + suffix); + while (result.exists()) { + result = new File(tmpdir, prefix + System.currentTimeMillis() + suffix); + } + if (!result.mkdirs()) { + throw new IOException("Can't create temporary directory: " + result); + } + return result; + } + /** + * Permet de creer un nouveu repertoire temporaire, l'effacement du + * r�pertoire est a la charge de l'appelant + * @param prefix + * @param suffix + * @return + * @throws java.io.IOException + */ + static public File createTempDirectory(String prefix, String suffix) throws IOException { + return createTempDirectory(prefix, suffix, null); + } + + /** + * Regarde si le fichier f1 est plus recent que le fichier f2 + * @param f1 + * @param f2 + * @return vrai si f1 est plus recent que f2 + */ + static public boolean isNewer(File f1, File f2) { + boolean result = f1.lastModified() > f2.lastModified(); + return result; + } + + /** + * Permet de lire un fichier et de retourner sont contenu sous forme d'une + * chaine de carateres + * @param file le fichier a lire + * @throws IOException + * @return + */ + static public String readAsString(File file) throws IOException { + StringBuffer result = new StringBuffer(); + char [] cbuf = new char[2000]; + BufferedReader in = getReader(file); + int nb = in.read(cbuf); + while (nb != -1) { + result.append(cbuf, 0, nb); + nb = in.read(cbuf); + } + in.close(); + return result.toString(); + } + + /** + * Permet de sauver une chaine directement dans un fichier + * @param file Le fichier dans lequel il faut ecrire la chaine + * @param content Le texte a ecrire dans le fichier + * @throws IOException if any pb while writing + */ + static public void writeString(File file, String content) throws IOException { + file.getParentFile().mkdirs(); + BufferedWriter out = getWriter(file); + out.write(content); + out.close(); + } + + /** + * Permet de sauver une chaine directement dans un fichier + * @param file Le fichier dans lequel il faut ecrire la chaine + * @param content Le texte a ecrire dans le fichier + * @param encoding encoding to use + * @throws IOException if any pb while writing + */ + static public void writeString(File file, String content,String encoding) throws IOException { + file.getParentFile().mkdirs(); + BufferedWriter out = getWriter(file,encoding); + out.write(content); + out.close(); + } + + /** + * Permet de donner une representation fichier pour une chaine de caractere. + * Le fichier sera automatiquement effac� � la fin de la JVM. + * @param content le contenu du fichier temporaire + * @return le fichier qui contient content + * @throws IOException + */ + static public File getTempFile(String content) throws IOException { + return getTempFile(content, ""); + } + + /** + * Permet de donner une representation fichier pour une chaine de caractere. + * Le fichier sera automatiquement effac� � la fin de la JVM. + * @param content le contenu du fichier temporaire + * @param fileSuffix l'extension du fichier cr�� + * @return le fichier qui contient content + * @throws IOException + */ + static public File getTempFile(String content, String fileSuffix) throws IOException { + File result = File.createTempFile("tmp-" + FileUtil.class.getName(), fileSuffix); + result.deleteOnExit(); + writeString(result, content); + return result; + } + + /** + * Equivalent de la methode basename unix. + * basename("/tmp/toto.xml", ".xml") -> "toto" + * + * @param file le fichier dont on souhaite le nom sans le chemin + * @param suffixes si present represente le suffixe a eliminer du fichier + * s'il est trouv� + * @return le nom du fichier sans le suffixe si trouv�. + */ + static public String basename(File file, String ... suffixes) { + String result = file.getName(); + for(String suffixe : suffixes) { + if (result.endsWith(suffixe)){ + result = result.substring(0, result.length() - suffixe.length()); + break; + } + } + return result; + } + + /** + * Permet de r�cup�rer l'extension d'un fichier + * @param file le fichier dont on souhaite l'extension + * @param extchars la liste des caracteres pouvant former l'extension + * dans l'ordre de preference. Si vide on utilise ".". + * @return l'extension ou la chaine vide si le fichier n'a pas d'extension + * l'extension ne contient pas le chaine de delimitation + */ + static public String extension(File file, String ... extchars) { + String result = ""; + String name = file.getName(); + + if(extchars.length == 0) { + extchars = new String[]{"."}; + } + for (String extchar : extchars) { + int pos = name.lastIndexOf(extchar); + if (pos != -1) { + result = name.substring(pos + extchar.length()); + break; + } + } + return result; + } + + static public interface FileAction { + public boolean doAction(File f); + } + + /** + * Retourne tous les sous r�pertoires du r�pertoire pass� en argument. + * @param directory un r�pertoire + * @return une liste d'objet {@link java.io.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> getSubDirectories(File directory) { + class DirectoryFilter implements FileFilter { + public boolean accept(File f) { + return f.isDirectory(); + } + } + return getFilteredElements(directory, new DirectoryFilter(), true); + } + + /** + * Retourne tous les fichiers du r�pertoire pass� en argument. + * @param directory un r�pertoire + * @return une liste d'objet {@link java.io.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> getFiles(File directory) { + class NormalFileFilter implements FileFilter { + public boolean accept(File f) { + return f.isFile(); + } + } + return getFilteredElements(directory, new NormalFileFilter(), true); + } + + /** + * Retourne les fichiers d'un r�pertoire qui s'attisfont un certain pattern. + * La recherche est faite r�cursivement dans les sous r�pertoires + * @param directory le r�pertoire � partir duquel il faut faire la recherche + * @param pattern le pattern que doit respecter le fichier pour �tre dans la + * liste r�sultante + * @param recursively + * @return une liste d'objet {@link java.io.File} qui ont s'attisfait le + * pattern. + */ + public static List<File> find(File directory, final String pattern, boolean recursively){ + final String root = directory.getAbsolutePath(); + final int rootLength = root.length(); + + return getFilteredElements(directory, new FileFilter() { + public boolean accept(File f) { + String longFilename = f.getAbsolutePath(); + // + 1 to remove the first / or \ + String filename = longFilename.substring(rootLength + 1); + return filename.matches(pattern); + } + }, recursively); + } + + /** + * Retourne la liste de toutes les fichiers ou r�pertoire qui s'attisfont + * le filtre + * @param directory repertoire � partir duquel il faut faire la recherche + * @param ff le filtre � appliquer pour savoir si le fichier parcouru doit + * �tre conserv� dans les r�sultats, ou null pour tous les fichiers + * @param recursively + * @return une liste d'objet {@link java.io.File}, qui s'attisfont le filtre + */ + public static List<File> getFilteredElements(File directory, FileFilter ff, boolean recursively) { + ArrayList<File> result = new ArrayList<File>(); + LinkedList<File> todo = new LinkedList<File>(); + if (directory.isDirectory()){ + todo.addAll(Arrays.asList(directory.listFiles())); + } + while(todo.size() > 0){ + File file = todo.removeFirst(); + if (recursively && file.isDirectory()){ + File [] childs = file.listFiles(); + if (childs != null) { // null if we don't have access to directory + todo.addAll(Arrays.asList(childs)); + } + } + if(ff == null || ff.accept(file)){ + result.add(file); + } + } + return result; + } + + /** + * Supprime recursivement tout le contenu d'un r�pertoire. + * @param directory + * @return vrai si tout se passe bien, false si la suppression d'un �lement + * se passe mal + */ + public static boolean deleteRecursively(String directory) { + return deleteRecursively(new File(directory)); + } + + /** + * Supprime recursivement tout le contenu d'un r�pertoire. + * @param directory + * @return vrai si tout se passe bien, false si la suppression d'un �lement + * se passe mal + */ + public static boolean deleteRecursively(File directory) { + return walkBefore(directory, new FileAction(){ + public boolean doAction(File f) { + return f.delete(); + } + }); + } + + /** + * 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. + * @param f le fichier ou r�pertoire � partir duquel il faut commencer + * @param fileAction l'action � effectuer sur chaque fichier + * @return le r�sultat des fileAction execut� sur les fichiers, chaque + * r�sultat de FileAction sont assembl� par un ET logique pour donner + * le r�sultat final + */ + public static boolean walkAfter(File f, FileAction fileAction) { + boolean result=fileAction.doAction(f); + if (f.isDirectory()) { + File list[] = f.listFiles(); + for (int i = 0; i < list.length; i++) { + result=result && walkAfter(list[i], fileAction); + } + } + return result; + } + + /** + * 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. + * @param f le fichier ou r�pertoire � partir duquel il faut commencer + * @param fileAction l'action � effectuer sur chaque fichier + * @return le r�sultat des fileAction execut� sur les fichiers, chaque + * r�sultat de FileAction sont assembl� par un ET logique pour donner + * le r�sultat final + */ + public static boolean walkBefore(File f, FileAction fileAction) { + boolean result=true; + if (f.isDirectory()) { + File list[] = f.listFiles(); + for (int i = 0; i < list.length; i++) { + result=result && walkBefore(list[i], fileAction); + } + } + return result && fileAction.doAction(f); + } + + /** + * Permet de copier le fichier source vers le fichier cible. + * @param source le fichier source + * @param target le fichier cible + * @throws IOException Erreur de copie + */ + public static void copy(File source, File target) throws IOException { + target.getParentFile().mkdirs(); + FileChannel sourceChannel = new FileInputStream(source).getChannel(); + FileChannel targetChannel = new FileOutputStream(target).getChannel(); + sourceChannel.transferTo(0, sourceChannel.size(), targetChannel); + // or + // targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); + sourceChannel.close(); + targetChannel.close(); + } + + /** + * Permet de copier le fichier source vers le fichier cible. + * @param source le fichier source + * @param target le fichier cible + * @throws IOException Erreur de copie + */ + public static void copy(String source, String target) throws IOException { + copy(new File(source), new File(target)); + } + + /** + * Copie recursivement le repertoire source dans le repertoire destination + * + * copyRecursively("/truc/titi", "/var/tmp") donnera le repertoire + * "/var/tmp/titi" + * + * @param srcDir + * @param destDir + * @param includePatterns les patterns que doivent resperter les + * fichiers/repertoires pour etre copi�. Si vide alors tout est copi� + * + * @throws IOException + */ + static public void copyRecursively(File srcDir, File destDir, String ... includePatterns) throws IOException { + copyAndRenameRecursively(srcDir, destDir, null, null, 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' + * + * @param srcDir + * @param destDir + * @param renameFrom pattern to permit rename file before uncompress it + * @param renameTo new name for file if renameFrom is applicable to it + * you can use $1, $2, ... if you have '(' ')' in renameFrom + * @param includePatterns les patterns que doivent resperter les + * fichiers/repertoires pour etre copi�. Si vide alors tout est copi� + * + * @throws IOException + */ + static public void copyAndRenameRecursively(File srcDir, File destDir, + String renameFrom, String renameTo, String ... includePatterns) throws IOException { + copyAndRenameRecursively(srcDir, destDir, true, renameFrom, renameTo, false, 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' + * + * @param srcDir + * @param destDir + * @param includeSrcDir si vrai alors le repertoire source est copie dans le + * repertoire destination et non pas seulement les fichiers qu'il contient + * @param renameFrom pattern to permit rename file before uncompress it + * @param renameTo new name for file if renameFrom is applicable to it + * you can use $1, $2, ... if you have '(' ')' in renameFrom + * @param exclude inverse include pattern interpretation + * @param includePatterns les patterns que doivent resperter les + * fichiers/repertoires pour etre copi�. Si vide alors tout est copi� + * + * @throws IOException + */ + static public void copyAndRenameRecursively(File srcDir, File destDir, + boolean includeSrcDir, String renameFrom, String renameTo, boolean exclude, + String ... includePatterns) throws IOException { + String rootSrc; + if (includeSrcDir) { + rootSrc = srcDir.getParent(); + } else { + rootSrc = srcDir.getPath(); + } + List<File> files = getFilteredElements(srcDir, null, true); + log.debug("copyRecursively: " + files); + for (File file : files) { + boolean doCopy = copyRecursivelyAccept(file, includePatterns); + if (xor(exclude, doCopy)) { + String path = file.getPath().substring(rootSrc.length()); + if (renameFrom != null && renameTo != null) { + String tmp = path.replaceAll(renameFrom, renameTo); + if (log.isDebugEnabled()) { + log.debug("rename " + path + " -> " + tmp); + } + path = tmp; + } + + File destFile = new File(destDir, path); + if (file.isDirectory()) { + log.debug("create directory: " + destFile); + destFile.mkdirs(); + } else { + log.debug("copy " + path + " to " + destFile); + copy(file, destFile); + } + } + } + } + + static private boolean xor(boolean b, boolean c) { + if (b) return !c; + else return c; + } + + /** + * @param file + * @param includePatterns + * @return + */ + private static boolean copyRecursivelyAccept(File file, String[] includePatterns) { + boolean result = includePatterns.length == 0; + String filename = file.getAbsolutePath(); + for (String pattern : includePatterns) { + result = filename.matches(pattern); + if (result) { + break; + } + } + return result; + } + +} // FileUtil + Property changes on: trunk/lutinutil-io/src/main/java/org/codelutin/util/FileUtil.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: trunk/lutinutil-io/src/main/java/org/codelutin/util/PropertiesDateRemoveFilterStream.java (from rev 949, trunk/lutinutil/src/main/java/org/codelutin/util/PropertiesDateRemoveFilterStream.java) =================================================================== --- trunk/lutinutil-io/src/main/java/org/codelutin/util/PropertiesDateRemoveFilterStream.java (rev 0) +++ trunk/lutinutil-io/src/main/java/org/codelutin/util/PropertiesDateRemoveFilterStream.java 2008-07-31 20:35:40 UTC (rev 952) @@ -0,0 +1,50 @@ +/* +* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package org.codelutin.util; + +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +public class PropertiesDateRemoveFilterStream extends FilterOutputStream { + + private boolean firstLineOver; + char endChar; + + public PropertiesDateRemoveFilterStream(OutputStream out) { + super(out); + firstLineOver = false; + String lineSeparator = java.security.AccessController + .doPrivileged(new sun.security.action.GetPropertyAction( + "line.separator")); + endChar = lineSeparator.charAt(lineSeparator.length() - 1); + } + + @Override + public void write(int b) throws IOException { + if (!firstLineOver) { + char c = (char) b; + if (c == endChar) { + firstLineOver = true; + } + } else { + out.write(b); + } + } + +} \ No newline at end of file Copied: trunk/lutinutil-io/src/main/java/org/codelutin/util/SortedProperties.java (from rev 949, trunk/lutinutil/src/main/java/org/codelutin/util/SortedProperties.java) =================================================================== --- trunk/lutinutil-io/src/main/java/org/codelutin/util/SortedProperties.java (rev 0) +++ trunk/lutinutil-io/src/main/java/org/codelutin/util/SortedProperties.java 2008-07-31 20:35:40 UTC (rev 952) @@ -0,0 +1,62 @@ +/* *##% + * Copyright (C) 2007 + * I18nPlugin, Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.codelutin.util; + +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; +import java.util.Properties; +import java.util.Vector; + +/** + * Permet d'avoir les fichiers de propri�t�s tri�s. + * + * @author julien + */ +public class SortedProperties extends Properties { + + private static final long serialVersionUID = -1147150444452577558L; + + + public SortedProperties() { + super(); + } + + public SortedProperties(Properties defaults) { + super(defaults); + } + + @Override + public synchronized Enumeration<Object> keys() { + List<Object> objects = Collections.list(super.keys()); + Vector<Object> result; + try { + // Attention, si les clef ne sont pas des string, ca ne marchera pas + List<String> list = CollectionUtil.toGenericList(objects, String.class); + Collections.sort(list); + result = new Vector<Object>(list); + } catch (IllegalArgumentException e) { + // keys are not string !!! + // can not sort keys + result = new Vector<Object>(objects); + } + return result.elements(); + } +} Property changes on: trunk/lutinutil-io/src/main/java/org/codelutin/util/SortedProperties.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: trunk/lutinutil-io/src/main/java/org/codelutin/util/StringUtil.java (from rev 949, trunk/lutinutil/src/main/java/org/codelutin/util/StringUtil.java) =================================================================== --- trunk/lutinutil-io/src/main/java/org/codelutin/util/StringUtil.java (rev 0) +++ trunk/lutinutil-io/src/main/java/org/codelutin/util/StringUtil.java 2008-07-31 20:35:40 UTC (rev 952) @@ -0,0 +1,552 @@ +/* *##%% + * Copyright (C) 2002, 2003 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%%**/ +/* * + * StringUtil.java + * + * Created: Sun Apr 14 2002 + * + * @author POUSSIN Benjamin <bpoussin@free.fr> + * Copyright Code Lutin + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +package org.codelutin.util; + +import java.awt.Color; +import java.lang.reflect.Field; +import java.text.DateFormat; +import java.text.MessageFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +/** + * Classe contenant un ensemle de methode static utiles pour la manipulation des + * chaine de caractere mais qui ne sont pas defini dans la classe String de + * Java. + * + * @author poussin + * @created 21 octobre 2003 + */ +public class StringUtil { // StringUtil + + /** Constructor for the StringUtil object */ + protected StringUtil() { + } + + /** + * Cette methode retire les accents. Quand le caractere est connu, elle le + * remplace par une version sans accent sinon, elle le supprime. + * Les caracteres non-alphanumeriques sont supprimes. + * + * @param s la chaine a unaccentuer + * @return la chaine sans accent + */ + static public String unaccent(String s) { + String result = ""; + for (char c : s.toCharArray()) { + if ("����".indexOf(c) != -1) { + result += "e"; + } else if ("���".indexOf(c) != -1) { + result += "a"; + } else if ("�".indexOf(c) != -1) { + result += "c"; + } else if ("��".indexOf(c) != -1) { + result += "i"; + } else if ("��".indexOf(c) != -1) { + result += "o"; + } else if ("���".indexOf(c) != -1) { + result += "u"; + } else if ("����".indexOf(c) != -1) { + result += "E"; + } else if ("���".indexOf(c) != -1) { + result += "A"; + } else if ("�".indexOf(c) != -1) { + result += "C"; + } else if ("��".indexOf(c) != -1) { + result += "I"; + } else if ("��".indexOf(c) != -1) { + result += "O"; + } else if ("���".indexOf(c) != -1) { + result += "U"; + } else if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') + || ('0' <= c && c <= '9') || ('.' == c) || ('-' == c) + || ('_' == c)) { + result += c; + } else { + // on ne l'ajoute pas a result donc on supprime le caractere + // result += encodeUTF(c); + } + } + return result; + } + + static public String substring(String s, int begin) { + String result; + result = substring(s, begin, s.length()); + return result; + } + + static public String substring(String s, int begin, int end) { + if (begin < 0) { + begin = s.length() + begin; + } + if (end < 0) { + end = s.length() + end; + } + if (end < begin) { + end = begin; + } + + String result; + result = s.substring(begin, end); + return result; + } + + /** + * Met en majuscule le premier caractere de la chaine passee en parametre + * + * @param word La chaine a capitaliser + * @return La chaine capitalisee + * @deprecated you must use + * org.apache.commons.lang.StringUtils.capitalise(String) + */ + public static String capitalize(String word) { + return word.substring(0, 1).toUpperCase() + word.substring(1); + } + + /** + * Met en minuscule le premier caractere de la chaine passe en parametre + * + * @param word La chaine a decapitaliser + * @return La chaine decapitalisee + * @deprecated you must use + * org.apache.commons.lang.StringUtils.uncapitalise(String) + */ + public static String uncapitalize(String word) { + return word.substring(0, 1).toLowerCase() + word.substring(1); + } + + /** + * Concat�ne un tableau de chaine de caracteres en une seul chaine. + * + * @param s le tableau de chaines + * @param sep le separateur a utiliser pour separer chaque chaine. + * @return la chaine resultante de la concatenation. Si le tableau est null + * ou vide, la chaine resultante est une chaine vide. + * @deprecated you must use org.apache.commons.lang.StringUtils.join + */ + public static String unsplit(String[] s, String sep) { + if (s == null || s.length <= 0) { + return ""; + } + + StringBuffer result = new StringBuffer(s[0]); + for (int i = 1; i < s.length; i++) { + result.append(sep).append(s[i]); + } + return result.toString(); + } + + private static final Character[] openingChars = {'(', '{', '['}; + + private static final Character[] closingChars = {')', '}', ']'}; + + /** + * Split string use 'separator' as separator. If String contains "'()[]{} + * this method count the number of open char end close char to split + * correctly argument + * + * @param args string to split + * @param separator separator use to split string + * @return array of string + */ + static public String[] split(String args, String separator) { + return split(openingChars, closingChars, args, separator); + } + + + /** + * Use to split string array representation in array according with swixat + * seperator list + * + * @param stringList string that represent array + * @return array with length > 0 if listAsString != null or null + */ + static public String[] split(String stringList) { + String[] result; + result = split(stringList, ","); + return result; + } + + /** + * Split string use 'separator' as separator. If String contains "' + * and <code>openingChar</code> <code>closingChars</code> + * <p/> + * this method count the number of open char end close char to split correctly + * argument + * + * @param openingChars list of opening caracteres + * @param closingChars list of closing caracteres + * @param args string to split + * @param separator separator use to split string + * @return array of string + */ + static public String[] split(Character[] openingChars, + Character[] closingChars, + String args, String separator) { + if (args == null) { + return new String[0]; + } + + List<String> result = new ArrayList<String>(); + + int start = 0; + int end; + StringBuffer op = new StringBuffer(); // stack of {([< currently open + char last = '\0'; // contains " or ' if string is openned + + List<Character> opening = Arrays.asList(openingChars); + + List<Character> closing = Arrays.asList(closingChars); + + for (int i = 0; i < args.length(); i++) { + char c = args.charAt(i); + if (c == '\\') { + // pass next char + i++; + } else if (last != '"' && last != '\'') { + if (opening.contains(c)) { + op.append(c); + } else if (closing.contains(c)) { + op.deleteCharAt(op.length() - 1); + } else if (c == '"' || c == '\'') { + // open string " or ' + last = c; + } else if (op.length() == 0 && + args.regionMatches(i, separator, 0, separator.length())) { + // end of one arguement + end = i; + // pass separator + i += separator.length() - 1; + + String a = args.substring(start, end); + result.add(a); + // start of next argument + start = end + separator.length(); + } + } else if (c == last) { + // close string " or ' + last = '\0'; + } + } + + if (start < args.length()) { + String a = args.substring(start, args.length()); + result.add(a); + } + + return result.toArray(new String[result.size()]); + } + + public static boolean toBoolean(String s) { + return "true".equalsIgnoreCase(s); + } + + public static byte toByte(String s) { + return Byte.parseByte(s); + } + + public static double toDouble(String s) { + return Double.parseDouble(s); + } + + public static float toFloat(String s) { + return Float.parseFloat(s); + } + + public static long toLong(String s) { + return Long.parseLong(s); + } + + public static short toShort(String s) { + return Short.parseShort(s); + } + + public static int toInt(String s) { + return Integer.parseInt(s); + } + + public static char toChar(String s) { + // fixme a revoir + return s.charAt(0); + } + + public static boolean[] toArrayBoolean(String... s) { + boolean[] result = new boolean[s.length]; + for (int i = 0; i < result.length; i++) { + result[i] = toBoolean(s[i]); + } + return result; + } + + public static byte[] toArrayByte(String... s) { + byte[] result = new byte[s.length]; + for (int i = 0; i < result.length; i++) { + result[i] = toByte(s[i]); + } + return result; + } + + public static double[] toArrayDouble(String... s) { + double[] result = new double[s.length]; + for (int i = 0; i < result.length; i++) { + result[i] = toDouble(s[i]); + } + return result; + } + + public static float[] toArrayFloat(String... s) { + float[] result = new float[s.length]; + for (int i = 0; i < result.length; i++) { + result[i] = toFloat(s[i]); + } + return result; + } + + public static long[] toArrayLong(String... s) { + long[] result = new long[s.length]; + for (int i = 0; i < result.length; i++) { + result[i] = toLong(s[i]); + } + return result; + } + + public static short[] toArrayShort(String... s) { + short[] result = new short[s.length]; + for (int i = 0; i < result.length; i++) { + result[i] = toShort(s[i]); + } + return result; + } + + public static int[] toArrayInt(String... s) { + int[] result = new int[s.length]; + for (int i = 0; i < result.length; i++) { + result[i] = toInt(s[i]); + } + return result; + } + + public static char[] toArrayChar(String... s) { + char[] result = new char[s.length]; + for (int i = 0; i < result.length; i++) { + result[i] = toChar(s[i]); + } + // fixme a revoir + return result; + } + + /** + * Essai de convertir une chaine de caractere en une couleur si possible si + * ce n'est pas possible retourne null. + * + * @param s la couleur sous la forme de string, par exemple "red", + * "yellow" ou bien en RGB "#FFAA99", et avec un canal alpha + * "#FFAA3366" + * @return la couleur demand� si possible sinon null + * @throws IllegalArgumentException + * @throws StringUtilException if any problem while conversion + */ + public static Color toColor(String s) throws StringUtilException { + try { + if (s.startsWith("#")) { + // r�cuperation des valeurs hexa + String hr = s.substring(1, 3); + String hg = s.substring(3, 5); + String hb = s.substring(5, 7); + + // conversion en entier + int r = Integer.parseInt(hr, 16); + int g = Integer.parseInt(hg, 16); + int b = Integer.parseInt(hb, 16); + + if (s.length() == 9) { + // s'il y a un canal alpha on l'utilise + String ha = s.substring(7, 9); + int a = Integer.parseInt(ha, 16); + return new Color(r, g, b, a); + } else { + return new Color(r, g, b); + } + } else { + Field f; + f = Color.class.getField(s); + return (Color) f.get(Color.class); + } + } catch (NumberFormatException e) { + throw new StringUtilException( + "Error during conversion from string to color", e); + } catch (SecurityException e) { + throw new StringUtilException( + "Error during conversion from string to color", e); + } catch (NoSuchFieldException e) { + throw new StringUtilException( + "Error during conversion from string to color", e); + } catch (IllegalArgumentException e) { + throw new StringUtilException( + "Error during conversion from string to color", e); + } catch (IllegalAccessException e) { + throw new StringUtilException( + "Error during conversion from string to color", e); + } + } + + public static Date toDate(String s) throws ParseException { + return DateFormat.getDateInstance().parse(s); + } + + static final protected double[] timeFactors = {1000000, 1000, 60, 60, 24}; + + static final protected String[] timeUnites = {"ns", "ms", "s", "m", "h", + "d"}; + + static public String convertTime(long value) { + return convert(value, timeFactors, timeUnites); + } + + static public String convertTime(long value,long value2) { + return convertTime(value2-value); + } + + static final protected double[] memoryFactors = {1024, 1024, 1024, 1024}; + + static final protected String[] memoryUnites = {"o", "Ko", "Mo", "Go", + "To"}; + + static public String convertMemory(long value) { + return convert(value, memoryFactors, memoryUnites); + } + + static public String convert(long value, double[] factors, String[] unites) { + long sign = value == 0 ? 1 : value / Math.abs(value); + int i = 0; + double tmp = Math.abs(value); + while (i < factors.length && i < unites.length && tmp > factors[i]) { + tmp = tmp / factors[i++]; + } + + tmp *= sign; + String result; + result = MessageFormat.format("{0,number,0.###}{1}", tmp, + unites[i]); + return result; + } + + /** + * V�rifie q'une chaine de caract�re est valid pour les bloc openner closer, ie. + * <p/> + * que les blocs d�finit par les deux caract�res s'entrechevauchent pas. + * <p/> + * Exemple avec '(' ')' : + * <p/> + * (a(b)) est valide, par contre ((aaa))) n'est pas valide + * + * @param txt txte a verifier + * @param opener le caract�re ouvrant + * @param closer le caract�re fermant + * @return <code>true</code> is la chaine est valide + */ + public static boolean checkEnclosure(String txt, final char opener, char closer) { + if (txt.indexOf(opener) == -1 && txt.indexOf(closer) == -1) { + // ok pas de block d�tect�s + return true; + } + List<Integer> opens = new ArrayList<Integer>(); + for (int i = 0; i < txt.length(); i++) { + char c = txt.charAt(i); + if (c == opener) { + // add a open block + opens.add(i); + continue; + } + if (c == closer) { + if (opens.isEmpty()) { + // problem no block left + return false; + } + // on supprime le dernier bloc + opens.remove(opens.size() - 1); + } + } + return opens.isEmpty(); + } + + /** + * Convertir un nom en une constante Java + * + * Les seuls caract�res autoris�s sont les alpha num�riques, ains + * que l'underscore. tous les autres caract�res seront ignor�s. + * + * @param name le nom � convertir + * @return la constante g�n�r�e + */ + public static String convertToConstantName(String name) { + StringBuilder sb = new StringBuilder(); + char lastChar=0; + for (int i = 0, j = name.length(); i < j; i++) { + char c = name.charAt(i); + if (Character.isDigit(c)) { + sb.append(c); + lastChar = c; + continue; + } + if (!Character.isLetter(c)) { + if (lastChar != '_') { + sb.append('_'); + } + lastChar='_'; + continue; + } + if (Character.isUpperCase(c)) { + if (!Character.isUpperCase(lastChar)&&lastChar!='_') { + sb.append('_'); + } + sb.append(c); + } else { + sb.append(Character.toUpperCase(c)); + } + lastChar=c; + } + String result = sb.toString(); + // clean tail + while (!result.isEmpty() && result.endsWith("_")) { + result = result.substring(0,result.length()-1); + } + // clean head + while (!result.isEmpty() && result.startsWith("_")) { + result = result.substring(1); + } + return result; + } + +} Property changes on: trunk/lutinutil-io/src/main/java/org/codelutin/util/StringUtil.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Copied: trunk/lutinutil-io/src/main/java/org/codelutin/util/StringUtilException.java (from rev 949, trunk/lutinutil/src/main/java/org/codelutin/util/StringUtilException.java) =================================================================== --- trunk/lutinutil-io/src/main/java/org/codelutin/util/StringUtilException.java (rev 0) +++ trunk/lutinutil-io/src/main/java/org/codelutin/util/StringUtilException.java 2008-07-31 20:35:40 UTC (rev 952) @@ -0,0 +1,24 @@ +/* + * Created on Dec 7, 2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.codelutin.util; + +/** + * @author pineau + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class StringUtilException extends RuntimeException { + + /** */ + private static final long serialVersionUID = 6148795384335489591L; + + public StringUtilException(String message, Exception e) { + super(message, e); + } + +} Property changes on: trunk/lutinutil-io/src/main/java/org/codelutin/util/StringUtilException.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native
participants (1)
-
tchemit@users.labs.libre-entreprise.org