new admin templates! with many thanks to init...
[mir.git] / source / mir / util / FileFunctions.java
index bdca26a..20d20e5 100755 (executable)
-package mir.util;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.FilenameFilter;\r
-\r
-import gnu.regexp.RE;\r
-\r
-public class FileFunctions {\r
-  protected static final int FILE_COPY_BUFFER_SIZE = 65536;\r
-\r
-  private FileFunctions() {\r
-  }\r
-\r
-  public static void copyFile(File aSourceFile, File aDestinationFile) throws IOException {\r
-    FileInputStream inputStream;\r
-    FileOutputStream outputStream;\r
-    int nrBytesRead;\r
-    byte[] buffer = new byte[FILE_COPY_BUFFER_SIZE];\r
-\r
-    inputStream = new FileInputStream(aSourceFile);\r
-    try {\r
-      File directory = new File(aDestinationFile.getParent());\r
-        if (directory!=null && !directory.exists()){\r
-          directory.mkdirs();\r
-      }\r
-      outputStream = new FileOutputStream(aDestinationFile);\r
-      try {\r
-        do {\r
-          nrBytesRead = inputStream.read(buffer);\r
-          if (nrBytesRead>0)\r
-            outputStream.write(buffer, 0, nrBytesRead);\r
-        }\r
-        while (nrBytesRead>=0);\r
-      }\r
-      finally {\r
-        outputStream.close();\r
-      }\r
-    }\r
-    finally {\r
-      inputStream.close();\r
-    }\r
-  }\r
-\r
-  public static void copyDirectory(File aSourceDirectory, File aDestinationDirectory) throws IOException {\r
-    int i;\r
-    File sourceFile;\r
-    File destinationFile;\r
-    File[] files = aSourceDirectory.listFiles();\r
-\r
-    if (!aDestinationDirectory.exists())\r
-      aDestinationDirectory.mkdirs();\r
-\r
-    for (i=0; i<files.length; i++) {\r
-      sourceFile = files[i];\r
-      destinationFile=new File(aDestinationDirectory, sourceFile.getName());\r
-      if (sourceFile.isDirectory()) {\r
-        if (!destinationFile.exists())\r
-          destinationFile.mkdir();\r
-        copyDirectory(sourceFile, destinationFile);\r
-      }\r
-      else {\r
-        copyFile(sourceFile, destinationFile);\r
-      }\r
-    }\r
-  }\r
-\r
-  public static void copy(File aSource, File aDestination) throws IOException {\r
-    if (aSource.isDirectory()) {\r
-      copyDirectory(aSource, aDestination);\r
-    }\r
-    else if (aDestination.isDirectory()) {\r
-      copyFile(aSource, new File(aDestination, aSource.getName()));\r
-    }\r
-    else {\r
-      copyFile(aSource, aDestination);\r
-    }\r
-  }\r
-\r
-  public static class RegExpFileFilter implements FilenameFilter {\r
-    private RE expression;\r
-\r
-    public RegExpFileFilter(String anExpression) {\r
-      try {\r
-        expression = new RE(anExpression);\r
-      }\r
-      catch (Throwable t) {\r
-        throw new RuntimeException(t.getMessage());\r
-      }\r
-    }\r
-\r
-    public boolean accept(File aDir, String aName) {\r
-      return expression.isMatch(aName) && !new File(aDir, aName).isDirectory();\r
-    }\r
-  }\r
-\r
-  public static class DirectoryFilter implements FilenameFilter {\r
-    public DirectoryFilter() {\r
-    }\r
-\r
-    public boolean accept(File aDir, String aName) {\r
-      return new File(aDir, aName).isDirectory();\r
-    }\r
-\r
-  }\r
-\r
+package mir.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.FilenameFilter;
+
+import gnu.regexp.RE;
+
+public class FileFunctions {
+  protected static final int FILE_COPY_BUFFER_SIZE = 65536;
+
+  private FileFunctions() {
+  }
+
+  public static void copyFile(File aSourceFile, File aDestinationFile) throws IOException {
+    FileInputStream inputStream;
+    FileOutputStream outputStream;
+    int nrBytesRead;
+    byte[] buffer = new byte[FILE_COPY_BUFFER_SIZE];
+
+    inputStream = new FileInputStream(aSourceFile);
+    try {
+      File directory = new File(aDestinationFile.getParent());
+        if (directory!=null && !directory.exists()){
+          directory.mkdirs();
+      }
+      outputStream = new FileOutputStream(aDestinationFile);
+      try {
+        do {
+          nrBytesRead = inputStream.read(buffer);
+          if (nrBytesRead>0)
+            outputStream.write(buffer, 0, nrBytesRead);
+        }
+        while (nrBytesRead>=0);
+      }
+      finally {
+        outputStream.close();
+      }
+    }
+    finally {
+      inputStream.close();
+    }
+  }
+
+  public static void copyDirectory(File aSourceDirectory, File aDestinationDirectory) throws IOException {
+    int i;
+    File sourceFile;
+    File destinationFile;
+    File[] files = aSourceDirectory.listFiles();
+
+    if (!aDestinationDirectory.exists())
+      aDestinationDirectory.mkdirs();
+
+    for (i=0; i<files.length; i++) {
+      sourceFile = files[i];
+      destinationFile=new File(aDestinationDirectory, sourceFile.getName());
+      if (sourceFile.isDirectory()) {
+        if (!destinationFile.exists())
+          destinationFile.mkdir();
+        copyDirectory(sourceFile, destinationFile);
+      }
+      else {
+        copyFile(sourceFile, destinationFile);
+      }
+    }
+  }
+
+  public static void copy(File aSource, File aDestination) throws IOException {
+    if (aSource.isDirectory()) {
+      copyDirectory(aSource, aDestination);
+    }
+    else if (aDestination.isDirectory()) {
+      copyFile(aSource, new File(aDestination, aSource.getName()));
+    }
+    else {
+      copyFile(aSource, aDestination);
+    }
+  }
+
+  public static class RegExpFileFilter implements FilenameFilter {
+    private RE expression;
+
+    public RegExpFileFilter(String anExpression) {
+      try {
+        expression = new RE(anExpression);
+      }
+      catch (Throwable t) {
+        throw new RuntimeException(t.getMessage());
+      }
+    }
+
+    public boolean accept(File aDir, String aName) {
+      return expression.isMatch(aName) && !new File(aDir, aName).isDirectory();
+    }
+  }
+
+  public static class DirectoryFilter implements FilenameFilter {
+    public DirectoryFilter() {
+    }
+
+    public boolean accept(File aDir, String aName) {
+      return new File(aDir, aName).isDirectory();
+    }
+
+  }
+
 }
\ No newline at end of file