mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add Handler
This commit is contained in:
@@ -3254,10 +3254,10 @@ public class FileUtil {
|
||||
*
|
||||
* @param file 文件
|
||||
* @param out 流
|
||||
* @return 目标文件
|
||||
* @return 写出的流byte数
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static File writeToStream(File file, OutputStream out) throws IORuntimeException {
|
||||
public static long writeToStream(File file, OutputStream out) throws IORuntimeException {
|
||||
return FileReader.create(file).writeToStream(out);
|
||||
}
|
||||
|
||||
@@ -3266,10 +3266,11 @@ public class FileUtil {
|
||||
*
|
||||
* @param fullFilePath 文件绝对路径
|
||||
* @param out 输出流
|
||||
* @return 写出的流byte数
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static void writeToStream(String fullFilePath, OutputStream out) throws IORuntimeException {
|
||||
writeToStream(touch(fullFilePath), out);
|
||||
public static long writeToStream(String fullFilePath, OutputStream out) throws IORuntimeException {
|
||||
return writeToStream(touch(fullFilePath), out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,5 +1,12 @@
|
||||
package cn.hutool.core.io.file;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.LineHandler;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -11,13 +18,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.LineHandler;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 文件读取器
|
||||
*
|
||||
@@ -249,20 +249,15 @@ public class FileReader extends FileWrapper {
|
||||
* 将文件写入流中
|
||||
*
|
||||
* @param out 流
|
||||
* @return File
|
||||
* @return 写出的流byte数
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public File writeToStream(OutputStream out) throws IORuntimeException {
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
in = new FileInputStream(file);
|
||||
IoUtil.copy(in, out);
|
||||
public long writeToStream(OutputStream out) throws IORuntimeException {
|
||||
try (FileInputStream in = new FileInputStream(this.file)){
|
||||
return IoUtil.copy(in, out);
|
||||
}catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
} finally {
|
||||
IoUtil.close(in);
|
||||
}
|
||||
return this.file;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------- Interface start
|
||||
|
Reference in New Issue
Block a user