package com.tofly.common.core.util.io;

import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;

/**
 * IO流工具类
 * 
 * @author liujiduo
 * 
 */
public class IOUtil {

    public final  static String TEMP_FILEPATH="temp/";

    /**
     * 关闭一个或多个流对象
     * 
     * @param closeables
     *            可关闭的流对象列表
     * @throws IOException
     */
    public static void close(Closeable... closeables) throws IOException {
        if (closeables != null) {
            for (Closeable closeable : closeables) {
                if (closeable != null) {
                    closeable.close();
                }
            }
        }
    }
 
    /**
     * 关闭一个或多个流对象
     * 
     * @param closeables
     *            可关闭的流对象列表
     */
    public static void closeQuietly(Closeable... closeables) {
        try {
            close(closeables);
        } catch (IOException e) {
            // do nothing
        }
    }

    /**
     * 将byte[]写到流中
     *
     * @param out 输出流
     * @param isCloseOut 写入完毕是否关闭输出流
     * @param content 写入的内容
     * @throws IOException IO异常
     */
    public static void write(OutputStream out, boolean isCloseOut, byte[] content) throws IOException {
        try {
            out.write(content);
        } catch (IOException e) {
            throw new IOException(e);
        } finally {
            if (isCloseOut) {
                close(out);
            }
        }
    }

    public static String getOs(){
        String osName=System.getProperty("os.name");
        if(osName.toLowerCase().contains("win")){
            return "windows";
        }else {
            return "linux";
        }
    }
 
}