From a9b693a0a599c66bfc36c1a000587dbc6b8dbdd5 Mon Sep 17 00:00:00 2001 From: LamGC Date: Thu, 26 Nov 2020 23:44:50 +0800 Subject: [PATCH] =?UTF-8?q?[Change]=20Framework-API=20=E5=9C=A8=20MessageS?= =?UTF-8?q?ender=20=E4=B8=AD=E7=9A=84=20'uploadImage(File)'=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AF=B9=E6=96=87=E4=BB=B6=E5=AD=98=E5=9C=A8=E4=B8=8E?= =?UTF-8?q?=E5=90=A6=E7=9A=84=E6=A3=80=E6=9F=A5;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Change] MessageSender 增加文件存在与否的检查; --- .../lamgc/cgj/bot/framework/message/MessageSender.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/MessageSender.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/MessageSender.java index e51f1fb..f8db272 100644 --- a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/MessageSender.java +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/MessageSender.java @@ -20,10 +20,7 @@ package net.lamgc.cgj.bot.framework.message; import net.lamgc.cgj.bot.framework.Platform; import net.lamgc.cgj.bot.framework.message.exception.UploadImageException; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; /** * 消息发送者. @@ -109,6 +106,9 @@ public interface MessageSender { * @throws UploadImageException 如果图片上传时发生异常可抛出. */ default String uploadImage(File imageFile) throws UploadImageException { + if (!imageFile.exists()) { + throw new UploadImageException(new FileNotFoundException(imageFile.getAbsolutePath())); + } try (InputStream imageInput = new FileInputStream(imageFile)) { return uploadImage(imageInput); } catch(Exception e) {