00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 package org.knopflerfish.framework;
00036
00037 import java.io.*;
00038
00039
00046 public class FileTree extends File
00047 {
00048
00052 public FileTree(String name) {
00053 super(name);
00054 }
00055
00056
00061 public FileTree(File file, String name) {
00062 super(file, name);
00063 }
00064
00065
00070 public FileTree(String n1, String n2) {
00071 super(n1, n2);
00072 }
00073
00074
00082 public void copyTo(File copyFile) throws IOException
00083 {
00084 if (isDirectory()) {
00085 copyFile.mkdirs();
00086 String [] dirs = list();
00087 for (int i = dirs.length - 1; i >= 0; i--) {
00088 (new FileTree(this, dirs[i])).copyTo(new File(copyFile, dirs[i]));
00089 }
00090 } else {
00091 InputStream is = null;
00092 OutputStream os = null;
00093 try {
00094 is = new BufferedInputStream(new FileInputStream(this));
00095 os = new BufferedOutputStream(new FileOutputStream(copyFile));
00096 byte[] buf=new byte[4096];
00097 for (;;) {
00098 int n=is.read(buf);
00099 if (n<0) {
00100 break;
00101 }
00102 os.write(buf, 0, n);
00103 }
00104 } finally {
00105 try {
00106 if (is != null) {
00107 is.close();
00108 }
00109 } finally {
00110 if (os != null) {
00111 os.close();
00112 }
00113 }
00114 }
00115 }
00116 }
00117
00118
00124 public boolean delete()
00125 {
00126 boolean allDeleted = true;
00127 if (isDirectory()) {
00128 String [] dirs = list();
00129 if(dirs != null) {
00130 for (int i = dirs.length - 1; i>= 0; i--) {
00131 allDeleted &= (new FileTree(this, dirs[i])).delete();
00132 }
00133 }
00134 }
00135 boolean thisDeleted = super.delete();
00136
00137 return allDeleted & thisDeleted;
00138 }
00139 }