package com.lms.common.util;
import java.io.*;
import java.nio.channels.FileChannel;
/**
* @Author: 李孟帅
* @Date: 2021-12-02 20:02
* @Description:
*/
public class IoUtil {
public static void copy(InputStream in, OutputStream out) throws IOException {
BufferedOutputStream bos = new BufferedOutputStream(out);
BufferedInputStream bis = new BufferedInputStream(in);
byte[] buf = new byte[1024];
int len;
while ((len = bis.read(buf)) != -1) {
bos.write(buf, 0, len);
}
}
public static void copy(FileInputStream in, FileOutputStream out) throws IOException {
FileChannel from = in.getChannel();
FileChannel to = out.getChannel();
long size = from.size();
for (long left = size; left > 0; ) {
left -= from.transferTo(size - left, left, to);
}
}
public static void copy(File src, File dest) throws IOException {
FileInputStream in = new FileInputStream(src);
FileOutputStream out = new FileOutputStream(dest);
copy(in, out);
close(in);
close(out);
}
public static void close(Closeable closeable) {
if (null != closeable) {
try {
closeable.close();
} catch (Exception ignored) {
}
}
}
}