Skip to content

Commit 2fa87a7

Browse files
committed
use custom InputStream traversal instead of a full byte array (SPR-9118)
1 parent fe57f74 commit 2fa87a7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

org.springframework.core/src/main/java/org/springframework/core/io/AbstractResource.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.net.URL;
2626

2727
import org.springframework.core.NestedIOException;
28-
import org.springframework.util.FileCopyUtils;
2928
import org.springframework.util.ResourceUtils;
3029

3130
/**
@@ -115,7 +114,22 @@ public File getFile() throws IOException {
115114
* @see #getInputStream()
116115
*/
117116
public long contentLength() throws IOException {
118-
return FileCopyUtils.copyToByteArray(getInputStream()).length;
117+
InputStream is = getInputStream();
118+
try {
119+
long size = 0;
120+
byte[] buf = new byte[255];
121+
for (int read = is.read(buf); read != -1;) {
122+
size += read;
123+
}
124+
return size;
125+
}
126+
finally {
127+
try {
128+
is.close();
129+
}
130+
catch (IOException ex) {
131+
}
132+
}
119133
}
120134

121135
/**

0 commit comments

Comments
 (0)