package com.openxc.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import android.os.Environment;
import android.util.Log;

/**
 * A file opener that uses Android's permission flags.
 *
 * This file opener will only work on an Android device.
 */
public class AndroidFileOpener implements FileOpener {
    private static final String TAG = "AndroidFileOpener";
    private static final String DEFAULT_DIRECTORY = "openxc/traces";

    private String mDirectory;

    public AndroidFileOpener(String directory) {
        mDirectory = directory;
    }

    @Override
    public BufferedWriter openForWriting(String filename) throws IOException {
        Log.i(TAG, "Opening " + getDirectory() + "/" + filename
                + " for writing on external storage");

        File externalStoragePath = Environment.getExternalStorageDirectory();
        File directory = new File(externalStoragePath.getAbsolutePath() +
                "/" + getDirectory());
        File file = new File(directory, filename);
        OutputStream outputStream = null;
        try {
            directory.mkdirs();
            outputStream = new FileOutputStream(file);
            return new BufferedWriter(new OutputStreamWriter(outputStream));
        } catch(IOException e) {
            Log.w(TAG, "Unable to open " + file + " for writing", e);
            throw e;
        } finally {
            if (outputStream != null) {
                outputStream.close();
            }
        }
    }

    private String getDirectory() {
        if(mDirectory == null) {
            return DEFAULT_DIRECTORY;
        }
        return mDirectory;
    }
}

@@ -1140,50 +1140,8 @@
 e);%0A
-        OutputStream outputStream = null;%0A
     
@@ -1186,32 +1186,45 @@
 ();%0A            
+OutputStream 
 outputStream = n
@@ -1455,120 +1455,8 @@
  e;%0A
-        %7D finally %7B%0A            if (outputStream != null) %7B%0A                outputStream.close();%0A            %7D%0A
     

Remove changes from AndroidFileOpener.java