package org.sana.net.http.handler;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 */
public class FileHandler implements ResponseHandler<File> {
    public static final String TAG = FileHandler.class.getSimpleName();

    final String path;

    public FileHandler(String path){
        this.path = path;
    }

    @Override
    public File handleResponse(HttpResponse response){
        File out = new File(path);
        if(out.exists()) out.delete();
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            try {
                FileOutputStream os = new FileOutputStream(out);
                InputStream is = entity.getContent();
                int inByte;
                while((inByte = is.read()) != -1) os.write(inByte);
                is.close();
                os.close();
            } catch(IOException ioe){
                ioe.printStackTrace();
            }
        }
        return out;
    }
}

@@ -423,16 +423,37 @@
 ng path;
+%0A    final File file;
 %0A%0A    pu
@@ -505,24 +505,154 @@
 ath = path;%0A
+        file = new File(path);%0A    %7D%0A%0A    public FileHandler(File file)%7B%0A        this.file = file;%0A        path = file.getPath();%0A
     %7D%0A%0A    @
@@ -727,49 +727,15 @@
     
-File out = new File(path);%0A        if(out
+if(file
 .exi
@@ -741,19 +741,20 @@
 ists()) 
-out
+file
 .delete(
@@ -913,19 +913,20 @@
 tStream(
-out
+file
 );%0A     
@@ -1246,11 +1246,12 @@
 urn 
-out
+file
 ;%0A  

Add File constructor