Skip to content

Commit 93b00bb

Browse files
zhuxiaolong37huiguangjun
authored andcommitted
Optimize file input stream conversion (#497)
1 parent 3f0a1a8 commit 93b00bb

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/main/java/com/aliyun/oss/common/utils/IOUtils.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,16 @@ public static boolean checkFile(File file) {
129129
public static InputStream newRepeatableInputStream(final InputStream original) throws IOException {
130130
InputStream repeatable = null;
131131
if (!original.markSupported()) {
132-
if (original instanceof FileInputStream) {
133-
repeatable = new RepeatableFileInputStream((FileInputStream) original);
134-
} else {
135-
repeatable = new BufferedInputStream(original, OSSConstants.DEFAULT_STREAM_BUFFER_SIZE);
132+
try {
133+
if (original instanceof FileInputStream) {
134+
repeatable = new RepeatableFileInputStream((FileInputStream) original);
135+
} else {
136+
repeatable = new BufferedInputStream(original, OSSConstants.DEFAULT_STREAM_BUFFER_SIZE);
137+
}
138+
} catch (Throwable e) {
139+
if (repeatable == null) {
140+
repeatable = original;
141+
}
136142
}
137143
} else {
138144
repeatable = original;

0 commit comments

Comments
 (0)