我正在使用链接使用HttpsURLConnection在大块文件中执行https帖子 -
file upload using httppost android
我得到致命异常 -
06-09 11:44:47.041 E/AndroidRuntime( 6250): FATAL EXCEPTION: Thread-712
06-09 11:44:47.041 E/AndroidRuntime( 6250): java.lang.OutOfMemoryError
06-09 11:44:47.041 E/AndroidRuntime( 6250): at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
06-09 11:44:47.041 E/AndroidRuntime( 6250): at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
06-09 11:44:47.041 E/AndroidRuntime( 6250): at libcore.net.http.RetryableOutputStream.write(RetryableOutputStream.java:61)
06-09 11:44:47.041 E/AndroidRuntime( 6250): at java.io.DataOutputStream.write(DataOutputStream.java:98)
HPROF分析 -
泄漏嫌疑人
" libcore.net.http.RetryableOutputStream"的一个实例;加载""占用134,216,008(82.46%)字节。存储器在" byte []"的一个实例中累积。由""。
加载详情
buf java.io.ByteArrayOutputStream @ 0x444fd460 16 134,215,984
content libcore.net.http.RetryableOutputStream @ 0x444fd448 24 134,216,008
out java.io.DataOutputStream @ 0x4467f918 24 48
有人可以帮我摆脱这个。
我也添加了DataOutputStream.flush
,但没有用
// read file and write to buffer
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
int pktSend = 0;
// continue till bytes read not null
while (bytesRead > 0) {
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
pktSend++;
dos.flush();
}
答案 0 :(得分:0)
也许您可以在代码上尝试以下设置:
// set the request mode as POST
urlConnection.setRequestMethod("POST");
// disable using cache.
urlConnection.setUseCaches(false);
// enable Output/Input.
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);