@@ -0,0 +1,2461 @@
+/* %0A * Licensed to the soi-toolkit project under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The soi-toolkit project licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.soitoolkit.commons.mule.file;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A/**%0A * Helper methods for the file-transport and file-handling in general.%0A * %0A * @author Magnus Larsson%0A *%0A */%0Apublic class FileUtil %7B%0A%0A%09private static final Logger logger = LoggerFactory.getLogger(FileUtil.class);%0A%0A%09/**%0A%09 * Hidden constructor.%0A%09 */%0A%09private FileUtil() %7B%0A%09%09throw new UnsupportedOperationException(%0A%09%09%09%09%22Not allowed to create an instance of this class%22);%0A%09%7D%0A%0A    public static void initFolder(File parent) throws IOException %7B%0A%0A    %09logger.debug(%22Init folder %22 + parent.getCanonicalPath());%0A    %09%0A    %09recursiveDelete(parent);%0A    %09boolean ok = parent.mkdirs();%0A    %09if (!ok) throw new IOException(%22Failed to recreate folder: %22 + parent);%0A%09%7D%0A%0A%09%0A    public static void recursiveDelete(File parent) throws IOException %7B%0A%0A    %09logger.debug(%22Recursive delete folder %22 + parent.getCanonicalPath());%0A%0A    %09// Bail out if the file/folder does not exist%0A        if(!parent.exists()) return;%0A    %09%0A    %09// If this file is a directory then first delete all its children%0A    %09if (parent.isDirectory()) %7B%0A    %09%09for (File child : parent.listFiles()) %7B%0A    %09%09%09recursiveDelete(child);%0A    %09%09%7D%0A    %09%7D%0A%0A    %09// Now delete this file, but first check write permissions on its parent...%0A    %09File parentParent = parent.getParentFile();%0A    %09if (!parentParent.canWrite()) %7B%0A%09%09%09if (!parentParent.setWritable(true)) throw new IOException(%22Failed to set readonly-folder: %22 + parentParent + %22 to writeable%22);%0A    %09%7D%0A    %09if (!parent.delete()) throw new IOException(%22Failed to delete folder: %22 + parent);%0A    %7D%0A%7D%0A

Update issue 73