Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 
 package org.apache.catalina.startup;
 
 import java.io.File;
 
Expand out a WAR in a Host's appBase.

Author(s):
Craig R. McClanahan
Remy Maucherat
Glenn L. Nielsen
Version:
$Revision: 1409 $
 
 
 public class ExpandWar {

    
Copy the specified file or directory to the destination.

Parameters:
src File object representing the source
dest File object representing the destination
 
     public static boolean copy(File srcFile dest) {
         
         boolean result = true;
         
         String files[] = null;
         if (src.isDirectory()) {
             files = src.list();
             result = dest.mkdir();
         } else {
             files = new String[1];
             files[0] = "";
         }
         if (files == null) {
             files = new String[0];
         }
         for (int i = 0; (i < files.length) && resulti++) {
             File fileSrc = new File(srcfiles[i]);
             File fileDest = new File(destfiles[i]);
             if (fileSrc.isDirectory()) {
                 result = copy(fileSrcfileDest);
             } else {
                 FileChannel ic = null;
                 FileChannel oc = null;
                 try {
                     ic = (new FileInputStream(fileSrc)).getChannel();
                     oc = (new FileOutputStream(fileDest)).getChannel();
                     ic.transferTo(0, ic.size(), oc);
                 } catch (IOException e) {
                     ..fileCopyError(fileSrcfileDeste);
                     result = false;
                 } finally {
                     if (ic != null) {
                         try {
                             ic.close();
                         } catch (IOException e) {
                         }
                     }
                     if (oc != null) {
                         try {
                             oc.close();
                         } catch (IOException e) {
                         }
                     }
                 }
             }
         }
         return result;
         
     }
    
    
    
Delete the specified directory, including all of its contents and sub-directories recursively. Any failure will be logged.

Parameters:
dir File object representing the directory to be deleted
    public static boolean delete(File dir) {
        // Log failure by default
        return delete(dirtrue);
    }

    
Delete the specified directory, including all of its contents and sub-directories recursively.

Parameters:
dir File object representing the directory to be deleted
logFailure true if failure to delete the resource should be logged
    public static boolean delete(File dirboolean logFailure) {
        boolean result;
        if (dir.isDirectory()) {
            result = deleteDir(dirlogFailure);
        } else {
            if (dir.exists()) {
                result = dir.delete();
            } else {
                result = true;
            }
        }
        if (logFailure && !result) {
        }
        return result;
    }
    
    
    
Delete the specified directory, including all of its contents and sub-directories recursively. Any failure will be logged.

Parameters:
dir File object representing the directory to be deleted
    public static boolean deleteDir(File dir) {
        return deleteDir(dirtrue);
    }

    
Delete the specified directory, including all of its contents and sub-directories recursively.

Parameters:
dir File object representing the directory to be deleted
logFailure true if failure to delete the resource should be logged
    public static boolean deleteDir(File dirboolean logFailure) {
        String files[] = dir.list();
        if (files == null) {
            files = new String[0];
        }
        for (int i = 0; i < files.lengthi++) {
            File file = new File(dirfiles[i]);
            if (file.isDirectory()) {
                deleteDir(filelogFailure);
            } else {
                file.delete();
            }
        }
        boolean result;
        if (dir.exists()) {
            result = dir.delete();
        } else {
            result = true;
        }
        
        if (logFailure && !result) {
        }
        
        return result;
    }
New to GrepCode? Check out our FAQ X