001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)DirectoryHelper.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.binding.shared.util;
030:
031: import java.io.File;
032:
033: import java.util.logging.Logger;
034:
035: /**
036: * DOCUMENT ME!
037: *
038: * @author Sun Microsystems, Inc.
039: */
040: public class DirectoryHelper {
041: /**
042: *
043: */
044: /**
045: *
046: */
047: /**
048: *
049: */
050: /**
051: *
052: */
053: /**
054: *
055: */
056: /**
057: *
058: */
059:
060: /**
061: *
062: */
063: private static Logger sLog = Logger
064: .getLogger("com.sun.jbi.binding.jms.util");
065:
066: /**
067: * Deletes a directory recursively.
068: *
069: * @param directoryOrFile directory or file that has to be deleted.
070: */
071: public static void deleteRecursively(File directoryOrFile) {
072: if (directoryOrFile == null) {
073: return;
074: }
075:
076: File directory = directoryOrFile;
077:
078: try {
079: if (directory.isFile()) {
080: directory.delete();
081:
082: return;
083: }
084:
085: File[] fileList = directory.listFiles();
086:
087: if (fileList == null) {
088: return;
089: }
090:
091: if (fileList.length == 0) {
092: directory.delete();
093:
094: return;
095: } else {
096: for (int i = 0; i < fileList.length; i++) {
097: if (fileList[i].isFile()) {
098: fileList[i].delete();
099: }
100:
101: if (fileList[i].isDirectory()) {
102: deleteRecursively(fileList[i]);
103: }
104: }
105:
106: directory.delete();
107:
108: return;
109: }
110: } catch (Exception e) {
111: sLog.info(directory.getAbsolutePath() + " "
112: + e.getMessage());
113: }
114:
115: return;
116: }
117: }
|