]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman-Common/src/org/splat/kernel/Do.java
Salome HOME
Modifications done to respect PMD rules. Versioning a document is fixed. Validation...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / kernel / Do.java
index c7702900d5dc5c5cdc00eb5c71f6a7ef61390c95..7c6d4f2bd7b6a0b489a3521ff529cc7f6a155490 100644 (file)
@@ -31,39 +31,70 @@ import org.splat.dal.bo.kernel.User;
 
 public class Do {
 
-    public static boolean containsIllicitCharacter (String name) {
+    public static boolean containsIllicitCharacter (final String name) {
 //  ------------------------------------------------------------               
       char parse[] = name.toCharArray();
          
       for (int i=0; i<parse.length; i++) {
         int k =  java.lang.Character.getType(parse[i]);
-        if (k == java.lang.Character.DECIMAL_DIGIT_NUMBER) continue;
-        if (k == java.lang.Character.LOWERCASE_LETTER)     continue;
-        if (k == java.lang.Character.UPPERCASE_LETTER)     continue;
-        if (k == java.lang.Character.SPACE_SEPARATOR)      continue;
-        if (k == java.lang.Character.END_PUNCTUATION)      continue;
-        if (k == java.lang.Character.DASH_PUNCTUATION)     continue;
-        if (parse[i] == '\'')                              continue;
-        if (parse[i] == '_')                               continue;
-        if (parse[i] == '&')                               continue;
-        if (parse[i] == '.')                               continue;
+        if (k == java.lang.Character.DECIMAL_DIGIT_NUMBER) {
+                       continue;
+               }
+        if (k == java.lang.Character.LOWERCASE_LETTER) {
+                       continue;
+               }
+        if (k == java.lang.Character.UPPERCASE_LETTER) {
+                       continue;
+               }
+        if (k == java.lang.Character.SPACE_SEPARATOR) {
+                       continue;
+               }
+        if (k == java.lang.Character.END_PUNCTUATION) {
+                       continue;
+               }
+        if (k == java.lang.Character.DASH_PUNCTUATION) {
+                       continue;
+               }
+        if (parse[i] == '\'') {
+                       continue;
+               }
+        if (parse[i] == '_') {
+                       continue;
+               }
+        if (parse[i] == '&') {
+                       continue;
+               }
+        if (parse[i] == '.') {
+                       continue;
+               }
         return true;
       }
       return false;
        }
 
-    public static void copy (File fromFile, File toFile) throws IOException {
+    public static void copy (final File fromFile, File toFile) throws IOException {
 //  ----------------------------------------------------
-      if (!fromFile.exists()) throw new IOException("ERROR File copy: no such '" + fromFile.getName() + "' source file.");
-      if (!fromFile.isFile()) throw new IOException("Error File copy: can't copy directory '" + fromFile.getName() + "'.");
+      if (!fromFile.exists()) {
+               throw new IOException("ERROR File copy: no such '" + fromFile.getName() + "' source file.");
+       }
+      if (!fromFile.isFile()) {
+               throw new IOException("Error File copy: can't copy directory '" + fromFile.getName() + "'.");
+       }
 
-      if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
-      if (toFile.exists())  throw new IOException("ERROR File copy: file " + toFile.getName() + " already exist.");
-      else {
+      if (toFile.isDirectory()) {
+               toFile = new File(toFile, fromFile.getName());
+       }
+      if (toFile.exists()) {
+               throw new IOException("ERROR File copy: file " + toFile.getName() + " already exist.");
+       } else {
         String parent = toFile.getParent();
-        if (parent == null) throw new IOException("ERROR File copy: destination directory not defined.");
+        if (parent == null) {
+                       throw new IOException("ERROR File copy: destination directory not defined.");
+               }
         File dir = new File(parent);
-        if (!dir.exists())  throw new IOException("ERROR File copy: destination directory " + parent + " doesn't exist.");
+        if (!dir.exists()) {
+                       throw new IOException("ERROR File copy: destination directory " + parent + " doesn't exist.");
+               }
       }
       FileInputStream from = null;
       FileOutputStream  to = null;
@@ -71,23 +102,40 @@ public class Do {
         from = new FileInputStream(fromFile);
         to = new FileOutputStream(toFile);
         byte[] buffer = new byte[4096];
-        int bytesRead;
+        int bytesRead = from.read(buffer);
 
-        while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);   // write
+        while (bytesRead != -1) {
+               to.write(buffer, 0, bytesRead);   // write
+               bytesRead = from.read(buffer);
+        }
         
         from.close();
         to.close();
       }
       catch (IOException e) {
-       throw new IOException();
+       throw e;
+      }
+      finally {
+         if (from != null) {
+                 from.close();
+         }
+         if (to != null) {
+                 to.close();
+         }
       }
     }
 
-       public static boolean sendMail (User to, String subject, String message, File attachement, Properties mprop) {
+       public static boolean sendMail (final User to, final String subject, final String message, final File attachement, final Properties mprop) {
 //  ------------------------------------------------------------------------------------------------------------
-         if (mprop.getProperty("mail.smtp.host") == null) return false;
-         if (mprop.getProperty("mail.pop3.host") == null) return false;
-         if (mprop.getProperty("mail.from")      == null) return false;
+         if (mprop.getProperty("mail.smtp.host") == null) {
+               return false;
+       }
+         if (mprop.getProperty("mail.pop3.host") == null) {
+               return false;
+       }
+         if (mprop.getProperty("mail.from")      == null) {
+               return false;
+       }
          
       Session mail = Session.getInstance(mprop, null);
       Logger  log  = Logger.getLogger(Do.class);