From a47dfd9850fcf7b24a9c9ebb2a1ccb68cf3c6fc7 Mon Sep 17 00:00:00 2001 From: zhuxiaolong37 Date: Wed, 27 Sep 2023 17:43:18 +0800 Subject: [PATCH] Optimize file input stream conversion --- .../java/com/aliyun/oss/common/utils/IOUtils.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/aliyun/oss/common/utils/IOUtils.java b/src/main/java/com/aliyun/oss/common/utils/IOUtils.java index 545e122f..bcaeda13 100644 --- a/src/main/java/com/aliyun/oss/common/utils/IOUtils.java +++ b/src/main/java/com/aliyun/oss/common/utils/IOUtils.java @@ -129,10 +129,16 @@ public static boolean checkFile(File file) { public static InputStream newRepeatableInputStream(final InputStream original) throws IOException { InputStream repeatable = null; if (!original.markSupported()) { - if (original instanceof FileInputStream) { - repeatable = new RepeatableFileInputStream((FileInputStream) original); - } else { - repeatable = new BufferedInputStream(original, OSSConstants.DEFAULT_STREAM_BUFFER_SIZE); + try { + if (original instanceof FileInputStream) { + repeatable = new RepeatableFileInputStream((FileInputStream) original); + } else { + repeatable = new BufferedInputStream(original, OSSConstants.DEFAULT_STREAM_BUFFER_SIZE); + } + } catch (Throwable e) { + if (repeatable == null) { + repeatable = original; + } } } else { repeatable = original;