shiyu6226

shiyu6226

V2EX 第 599401 号会员,加入于 2022-10-28 12:43:33 +08:00
根据 shiyu6226 的设置,主题列表被隐藏
二手交易 相关的信息,包括已关闭的交易,不会被隐藏
shiyu6226 最近回复了
2022-12-09 23:29:12 +08:00
回复了 shiyu6226 创建的主题 程序员 求助, Java 接口上传 2G 以上大文件 EOFException: null
@aguesuka
异常不在 service 也不在 controller ,我观察到的情况是 tomcat 缓存目录正在接收大文件时 到 2 个多 G 就中断 出异常了。
堆栈日志其实是打印全的,但是有点多,我就只发了主要的
2022-12-09 19:09:58 +08:00
回复了 shiyu6226 创建的主题 程序员 求助, Java 接口上传 2G 以上大文件 EOFException: null
@DinnyXu
控制层不是越简单越好嘛…
2022-12-09 14:37:12 +08:00
回复了 shiyu6226 创建的主题 程序员 求助, Java 接口上传 2G 以上大文件 EOFException: null
@Stendan
感谢,目前看来好像只有分片上传可行了
2022-12-09 14:33:08 +08:00
回复了 shiyu6226 创建的主题 程序员 求助, Java 接口上传 2G 以上大文件 EOFException: null
@zsj1029
@koloonps

实现方式是用的缓冲流写入的,实际运行过程中,内存使用一直保持在 500MB 上下,代码如下

private static boolean writeFileToLocal(String toLocalFilePath, MultipartFile file) throws Exception {
boolean flag = false;

BufferedOutputStream bufferedOutputStream = null;
BufferedInputStream bufferedInputStream = null;
try {
bufferedInputStream = new BufferedInputStream(file.getInputStream());
bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(toLocalFilePath));

int index;
byte[] bytes = new byte[4096];
while ((index = bufferedInputStream.read(bytes)) != -1) {
bufferedOutputStream.write(bytes, 0, index);
bufferedOutputStream.flush();
}
flag = true;
} catch (IOException e) {
log.error("文件写入失败," + e.getMessage());
if (new File(toLocalFilePath).exists()) {
new File(toLocalFilePath).delete();
}
throw new Exception(e.getMessage());
} finally {
if (bufferedOutputStream != null) {
try {
bufferedOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bufferedInputStream != null) {
try {
bufferedInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.gc();
}
2022-12-09 14:29:37 +08:00
回复了 shiyu6226 创建的主题 程序员 求助, Java 接口上传 2G 以上大文件 EOFException: null
2022-12-09 14:29:12 +08:00
回复了 shiyu6226 创建的主题 程序员 求助, Java 接口上传 2G 以上大文件 EOFException: null
@xiaohundun 这个是用在内网环境下的,网络应该是不受影响
2022-11-13 22:58:05 +08:00
回复了 overthemoon 创建的主题 问与答 Linux 软件安装位置
大部分应用如果默认安装的话 都在 /usr/local 下,但是一般服务器 /目录(系统分区)不会给的很大,所以应用都是单独放其他分区,我这边是 公司部署应用都是 /opt 下,个人部署 /home 下
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5878 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 02:11 · PVG 10:11 · LAX 19:11 · JFK 22:11
Developed with CodeLauncher
♥ Do have faith in what you're doing.