/*
 * Copyright 2013 wada811<at.wada811@gmail.com>
 *
 * Licensed 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 at.wada811.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.channels.FileChannel;

public class FileUtils {

    public static boolean copy(File srcFile, File distFile){
        if(!srcFile.exists()){
            return false;
        }
        distFile.mkdirs();
        if(!distFile.exists()){
            return false;
        }
        FileChannel srcChannel = null;
        FileChannel distChannel = null;
        try{
            srcChannel = new FileInputStream(srcFile).getChannel();
            distChannel = new FileOutputStream(distFile).getChannel();
            srcChannel.transferTo(0, srcChannel.size(), distChannel);
        }catch(FileNotFoundException e){
            e.printStackTrace();
            return false;
        }catch(IOException e){
            e.printStackTrace();
            return false;
        }finally{
            if(srcChannel != null){
                try{
                    srcChannel.close();
                }catch(IOException e){
                    e.printStackTrace();
                }
            }
            if(distChannel != null){
                try{
                    distChannel.close();
                }catch(IOException e){
                    e.printStackTrace();
                }
            }
        }
        return true;
    }

    public static boolean move(File srcFile, File distFile){
        boolean success = FileUtils.copy(srcFile, distFile);
        if(success){
            srcFile.delete();
        }
        return success;
    }

    public static String readFileString(String filePath){
        return FileUtils.readFileString(new File(filePath));
    }

    public static String readFileString(File file){
        BufferedReader br = null;
        StringBuilder builder = new StringBuilder();
        try{
            br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            String line;
            while((line = br.readLine()) != null){
                builder.append(line);
                builder.append("\n");
            }
        }catch(FileNotFoundException e){
            e.printStackTrace();
            return null;
        }catch(IOException e){
            e.printStackTrace();
            return null;
        }finally{
            if(br != null){
                try{
                    br.close();
                }catch(IOException e){
                    e.printStackTrace();
                }
            }
        }
        return builder.toString();
    }
}

@@ -1083,24 +1083,75 @@
         
-distFile
+if(srcFile.isFile())%7B%0D%0A            distFile.getParentFile()
 .mkdirs(
@@ -1150,24 +1150,28 @@
 .mkdirs();%0D%0A
+    
         if(!
@@ -1175,24 +1175,40 @@
 f(!distFile.
+getParentFile().
 exists())%7B%0D%0A
@@ -1199,32 +1199,36 @@
 e().exists())%7B%0D%0A
+    
             retu
@@ -1230,32 +1230,178 @@
  return false;%0D%0A
+            %7D%0D%0A        %7Delse%7B%0D%0A            distFile.mkdirs();%0D%0A            if(!distFile.exists())%7B%0D%0A                return false;%0D%0A            %7D%0D%0A
         %7D%0D%0A     

Fix #copy bug