package com.tzapps.common.utils;

import java.io.File;
import java.io.IOException;

import android.content.Context;
import android.net.Uri;
import android.util.Log;

public class FileUtils
{
    private static final String TAG = "FileUtils";

    public static File getTempFile(Context context, String url)
    {
        File file = null;
        try
        {
            String fileName = Uri.parse(url).getLastPathSegment();
            file = File.createTempFile(fileName, null, context.getCacheDir());
        }
        catch (IOException e)
        {
            Log.e(TAG, "getTempFile failed");
        }

        return file;
    }
    
}


@@ -63,27 +63,187 @@
 java.io.
-IOException
+FileInputStream;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.OutputStream;%0Aimport java.nio.channels.FileChannel
 ;%0A%0Aimpor
@@ -296,33 +296,8 @@
 Uri;
-%0Aimport android.util.Log;
 %0A%0Apu
@@ -374,366 +374,2183 @@
 s%22;%0A
+    
 %0A    
-public static File getTempFile(Context context, String url)%0A    %7B%0A        File file = null;%0A        try%0A        %7B%0A            String fileName = Uri.parse(url).getLastPathSegment();%0A            file = File.createTempFile(fileName, null, context.getCacheDir());%0A        %7D%0A        catch (IOException e)%0A        %7B%0A            Log.e(TAG, %22getTempFile failed%22
+/**%0A     * Copy a uri file to indicated file path%0A     * %0A     * @param context   the application context%0A     * @param uri       the uri file to copy%0A     * @param dest      the dest file %0A     * @throws IOException%0A     */%0A    public static void copyUriTo(Context context, Uri uri, File dest) throws IOException%0A    %7B%0A        InputStream input = null;%0A        OutputStream output = null;%0A        %0A        try%0A        %7B%0A            input = context.getContentResolver().openInputStream(uri);%0A            output = new FileOutputStream(dest);%0A            %0A            copyFileUsingStream(input, output);%0A        %7D%0A        finally%0A        %7B%0A            input.close();%0A            output.close();%0A        %7D%0A    %7D%0A    %0A    /**%0A     * Copy a file by using the file channels, it could be 10x faster than the traditional way of%0A     * copying file by using the file streams.%0A     * %0A     * @param src     the source file%0A     * @param dest    the destination file%0A     * @throws IOException%0A     */%0A    public static void copyFileUsingFileChannels(File src, File dest) throws IOException%0A    %7B%0A        FileChannel inputChannel = null;%0A        FileChannel outputChannel = null;%0A        %0A        try%0A        %7B%0A            inputChannel = new FileInputStream(src).getChannel();%0A            outputChannel = new FileOutputStream(dest).getChannel();%0A            outputChannel.transferFrom(inputChannel, 0, inputChannel.size());%0A        %7D%0A        finally%0A        %7B%0A            inputChannel.close();%0A            outputChannel.close();%0A        %7D%0A    %7D%0A    %0A    %0A    /**%0A     * Copy a file by using the file streams%0A     * %0A     * @param src     the source file%0A     * @param dest    the destination file%0A     * @throws IOException%0A     */%0A    public static void copyFileUsingFileStreams(File source, File dest) throws IOException%0A    %7B%0A        InputStream input = null;%0A        OutputStream output = null;%0A        %0A        try%0A        %7B%0A            input = new FileInputStream(source);%0A            output = new FileOutputStream(dest);%0A            %0A            copyFileUsingStream(input, output);%0A        %7D%0A        finally%0A        %7B%0A            input.close();%0A            output.close(
 );%0A 
@@ -2562,29 +2562,277 @@
   %7D%0A
+    %7D
 %0A    
+%0A
     
-return file;
+private static void copyFileUsingStream(InputStream in, OutputStream out) throws IOException%0A    %7B%0A        byte%5B%5D buf = new byte%5B1024%5D;%0A        int read;%0A        while ((read = in.read(buf)) != -1)%0A        %7B%0A            out.write(buf, 0, read);%0A        %7D
 %0A   

add a few useful file copy related functions into FileUtils