package com.reyun.saas.common.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class IOUtil {

    public static void close(OutputStream os) {
        if (os != null) {
            try {
                os.close();
            } catch (Exception ignored) {
            }
        }
    }

    public static void close(InputStream is) {
        if (is != null) {
            try {
                is.close();
            } catch (Exception ignored) {
            }
        }
    }

    public static long copy(InputStream in, OutputStream out)
            throws IOException {
        byte[] buffer = new byte[1024 * 4];
        int len;
        long count = 0;

        while ((len = in.read(buffer)) >= 0) {
            out.write(buffer, 0, len);
            count += len;
        }
        return count;
    }
}
