import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.util.List;
import java.util.Stack;
import org.tizen.common.util.log.Logger;
/**
* Copy all the files in the source directory to the destination directory.
* If destination directory does not exist, it is created.
- * If destination file already exists , it determines overwrite it or not by overwrite parameter.
+ * If destination file already exists , it determines overwriting by overwrite parameter.
* @param from source directory path
* @param to destination directory path
* @param overwrite if true, it overwrites. Else, skip copying.
* @throws IOException
*/
public static void copyRecursively(String from, String to, boolean overwrite) throws IOException {
+ copyRecursively(from, to, overwrite, null);
+ }
+
+ /**
+ * Copy all the files in the source directory to the destination directory except files in filters parameter.
+ * If destination directory does not exist, it is created.
+ * If destination file already exists , it determines overwriting by overwrite parameter.
+ * @param from
+ * @param to
+ * @param overwrite
+ * @param filter
+ * @throws IOException
+ */
+ public static void copyRecursively(String from, String to, boolean overwrite, File... filters) throws IOException {
File fromDir = new File(from);
File toDir = new File(to);
if (fromDir.exists() == false) {
return;
}
checkDirectory(fromDir, toDir);
- copyRecursivelyWithoutDirChecking(fromDir, toDir, overwrite);
+ copyRecursivelyWithoutDirChecking(fromDir, toDir, overwrite, filters);
}
private static void checkDirectory(File fromDir, File toDir) throws IOException {
}
}
- private static void copyRecursivelyWithoutDirChecking(File fromDir, File toDir, boolean overwrite) throws IOException {
+ private static void copyRecursivelyWithoutDirChecking(File fromDir, File toDir, boolean overwrite, File... filters) throws IOException {
Stack<File> fromFileStack = new Stack<File>();
Stack<File> toFileStack = new Stack<File>();
}
else if(fromFile.isFile()) {
if(!toFile.exists() || !toFile.isFile() || overwrite) {
- copyTo(fromFile, toFile, false);
+ if(filters != null) {
+ boolean found = false;
+ for(File filter: filters) {
+ if(filter.getCanonicalPath().equals(fromFile.getCanonicalPath())) {
+ found = true;
+ break;
+ }
+ }
+ if(!found) {
+ copyTo(fromFile, toFile, false);
+ }
+ }
+ else {
+ copyTo(fromFile, toFile, false);
+ }
}
}
}