package cn.i2edu.dubbing_lib.audioUtils.compose;

import android.text.TextUtils;

//import com.choucheng.dubbing_lib.exceptionengine.CustomBugReporter;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * Created by zhengtongyu on 16/5/23.
 */
@SuppressWarnings("ResultOfMethodCallIgnored")
public class FileFunction {

    public static void DeleteFile(String path) {
        if (!TextUtils.isEmpty(path)) {
            File file = new File(path);

            if (file.exists()) {
                try {
                    file.delete();
                } catch (Exception e) {
//                    LogFunction.error("删除本地文件失败", e);
                }
            }
        }
    }

    public static FileInputStream GetFileInputStreamFromFile(String fileUrl) {
        FileInputStream fileInputStream = null;

        try {
            File file = new File(fileUrl);

            fileInputStream = new FileInputStream(file);
        } catch (Exception e) {
            e.printStackTrace();
//            CustomBugReporter.reportError(FileFunction.class.getName(), "获取录音文件", e);
        }

        return fileInputStream;
    }

    public static FileOutputStream GetFileOutputStreamFromFile(String fileUrl) {
        FileOutputStream bufferedOutputStream = null;

        try {
            File file = new File(fileUrl);

            if (file.exists()) {
                file.delete();
            }

            file.createNewFile();

            bufferedOutputStream = new FileOutputStream(file);
        } catch (Exception e) {
//            LogFunction.error("GetFileOutputStreamFromFile异常", e);
        }

        return bufferedOutputStream;
    }

}
