1 22 23 package org.objectweb.petals.tools.jbicommon.util; 24 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.io.OutputStream ; 29 import java.util.logging.Level ; 30 import java.util.logging.Logger ; 31 32 40 public final class FileUtil { 41 42 private static final Logger LOGGER = Logger.getLogger(XMLUtil.class 43 .getName()); 44 45 49 private static final int DEFAULT_BUFFER_SIZE = 4096; 51 54 private FileUtil() { 55 super(); 56 } 57 58 65 public static void copyInputStream(final InputStream in, 66 final OutputStream out) throws IOException { 67 byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; 68 int len; 69 try { 73 while (true) { 74 len = in.read(buffer); 75 if (len == -1) { 76 break; 77 } 78 out.write(buffer); 79 } 80 } finally { 81 if (in != null) { 82 in.close(); 83 } 84 if (out != null) { 85 out.close(); 86 } 87 in.close(); 88 out.close(); 89 } 90 } 91 92 97 public static boolean removeDirectory(final File dir) { 98 99 boolean completeRemoval = true; 100 101 if (!dir.isDirectory() && !dir.exists()) { 102 return false; } 104 105 for (File aFile : dir.listFiles()) { 107 108 if (aFile.isDirectory()) { 109 completeRemoval = removeDirectory(aFile); 110 } else { 111 completeRemoval = aFile.delete(); 112 } 113 } 114 115 if (completeRemoval) { 116 completeRemoval = dir.delete(); 118 } else { 119 LOGGER.log(Level.WARNING, 121 "Directory not deleted because not empty :" 122 + dir.getAbsolutePath()); 123 } 124 125 return completeRemoval; 126 } 127 128 } 129 | Popular Tags |