Author: tchemit Date: 2008-08-16 12:39:44 +0000 (Sat, 16 Aug 2008) New Revision: 1030 Added: trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUtil.java Modified: trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUpdater.java trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUpdaterHelper.java trunk/lutinpluginutil/src/main/java/org/codelutin/util/MirroredFileUpdater.java trunk/lutinpluginutil/src/test/java/org/codelutin/util/JavaDummy.java trunk/lutinpluginutil/src/test/java/org/codelutin/util/JaxxDummy.java Log: ajout de FileUtil preparation pour les changements de licence Modified: trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUpdater.java =================================================================== --- trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUpdater.java 2008-08-16 10:04:38 UTC (rev 1029) +++ trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUpdater.java 2008-08-16 12:39:44 UTC (rev 1030) @@ -1,5 +1,5 @@ /** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * *##% Copyright (C) 2008 Code Lutin, Tony Chemit * 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 @@ -10,7 +10,7 @@ * 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; Modified: trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUpdaterHelper.java =================================================================== --- trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUpdaterHelper.java 2008-08-16 10:04:38 UTC (rev 1029) +++ trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUpdaterHelper.java 2008-08-16 12:39:44 UTC (rev 1030) @@ -1,5 +1,5 @@ /** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * *##% Copyright (C) 2008 Code Lutin, Tony Chemit * 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 @@ -10,7 +10,7 @@ * 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; Added: trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUtil.java =================================================================== --- trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUtil.java (rev 0) +++ trunk/lutinpluginutil/src/main/java/org/codelutin/util/FileUtil.java 2008-08-16 12:39:44 UTC (rev 1030) @@ -0,0 +1,102 @@ +/** + * *##% Copyright (C) 2008 Code Lutin, Tony Chemit + * 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.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.nio.channels.FileChannel; + +/** @author chemit */ +public class FileUtil { + + /** + * Permet de copier le fichier source vers le fichier cible. + * + * @param source le fichier source + * @param target le fichier cible + * @throws java.io.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 lire un fichier et de retourner sont contenu sous forme d'une + * chaine de carateres + * + * @param file le fichier a lire + * @param encoding encoding to read file + * @return the content of the file + * @throws IOException if IO pb + */ + static public String readAsString(File file, String encoding) throws IOException { + FileInputStream inf = new FileInputStream(file); + BufferedReader in = new BufferedReader(new InputStreamReader(inf, encoding)); + final String result = readAsString(in); + in.close(); + return result; + } + + /** + * Permet de lire un fichier et de retourner sont contenu sous forme d'une + * chaine de carateres + * + * @param file le reader a lire + * @return the content of the file + * @throws IOException if IO pb + */ + static public String readAsString(java.io.Reader file) throws IOException { + StringBuffer result = new StringBuffer(); + char[] cbuf = new char[2000]; + BufferedReader in = new BufferedReader(file); + int nb = in.read(cbuf); + while (nb != -1) { + result.append(cbuf, 0, nb); + nb = in.read(cbuf); + } + in.close(); + return result.toString(); + } + + /** + * Sauvegarde un contenu dans un fichier. + * + * @param file le fichier a ecrire + * @param content le contenu du fichier + * @param encoding l'encoding d'ecriture + * @throws IOException if IO pb + */ + static public void writeString(File file, String content, String encoding) throws IOException { + file.getParentFile().mkdirs(); + BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding)); + out.write(content); + out.close(); + } + +} Modified: trunk/lutinpluginutil/src/main/java/org/codelutin/util/MirroredFileUpdater.java =================================================================== --- trunk/lutinpluginutil/src/main/java/org/codelutin/util/MirroredFileUpdater.java 2008-08-16 10:04:38 UTC (rev 1029) +++ trunk/lutinpluginutil/src/main/java/org/codelutin/util/MirroredFileUpdater.java 2008-08-16 12:39:44 UTC (rev 1030) @@ -1,5 +1,5 @@ /** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * *##% Copyright (C) 2008 Code Lutin, Tony Chemit * 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 @@ -10,7 +10,7 @@ * 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; Modified: trunk/lutinpluginutil/src/test/java/org/codelutin/util/JavaDummy.java =================================================================== --- trunk/lutinpluginutil/src/test/java/org/codelutin/util/JavaDummy.java 2008-08-16 10:04:38 UTC (rev 1029) +++ trunk/lutinpluginutil/src/test/java/org/codelutin/util/JavaDummy.java 2008-08-16 12:39:44 UTC (rev 1030) @@ -1,5 +1,5 @@ /** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * *##% Copyright (C) 2008 Code Lutin, Tony Chemit * 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 @@ -10,7 +10,7 @@ * 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; Modified: trunk/lutinpluginutil/src/test/java/org/codelutin/util/JaxxDummy.java =================================================================== --- trunk/lutinpluginutil/src/test/java/org/codelutin/util/JaxxDummy.java 2008-08-16 10:04:38 UTC (rev 1029) +++ trunk/lutinpluginutil/src/test/java/org/codelutin/util/JaxxDummy.java 2008-08-16 12:39:44 UTC (rev 1030) @@ -1,5 +1,5 @@ /** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * *##% Copyright (C) 2008 Code Lutin, Tony Chemit * 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 @@ -10,7 +10,7 @@ * 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;