use custom InputStream traversal instead of a full byte array (SPR-9118)
This commit is contained in:
parent
fe57f74c1a
commit
2fa87a71fa
|
@ -25,7 +25,6 @@ import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import org.springframework.core.NestedIOException;
|
import org.springframework.core.NestedIOException;
|
||||||
import org.springframework.util.FileCopyUtils;
|
|
||||||
import org.springframework.util.ResourceUtils;
|
import org.springframework.util.ResourceUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,7 +114,22 @@ public abstract class AbstractResource implements Resource {
|
||||||
* @see #getInputStream()
|
* @see #getInputStream()
|
||||||
*/
|
*/
|
||||||
public long contentLength() throws IOException {
|
public long contentLength() throws IOException {
|
||||||
return FileCopyUtils.copyToByteArray(getInputStream()).length;
|
InputStream is = getInputStream();
|
||||||
|
try {
|
||||||
|
long size = 0;
|
||||||
|
byte[] buf = new byte[255];
|
||||||
|
for (int read = is.read(buf); read != -1;) {
|
||||||
|
size += read;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
catch (IOException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue