[Change] Framework-API 在 MessageSender 中的 'uploadImage(File)' 增加对文件存在与否的检查;

[Change] MessageSender 增加文件存在与否的检查;
This commit is contained in:
LamGC 2020-11-26 23:44:50 +08:00
parent a4ff698716
commit a9b693a0a5
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D

View File

@ -20,10 +20,7 @@ package net.lamgc.cgj.bot.framework.message;
import net.lamgc.cgj.bot.framework.Platform; import net.lamgc.cgj.bot.framework.Platform;
import net.lamgc.cgj.bot.framework.message.exception.UploadImageException; import net.lamgc.cgj.bot.framework.message.exception.UploadImageException;
import java.io.File; import java.io.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
/** /**
* 消息发送者. * 消息发送者.
@ -109,6 +106,9 @@ public interface MessageSender {
* @throws UploadImageException 如果图片上传时发生异常可抛出. * @throws UploadImageException 如果图片上传时发生异常可抛出.
*/ */
default String uploadImage(File imageFile) 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)) { try (InputStream imageInput = new FileInputStream(imageFile)) {
return uploadImage(imageInput); return uploadImage(imageInput);
} catch(Exception e) { } catch(Exception e) {