我在IntentService中下载文件时遇到致命异常。小文件下载得很好。但9MB + - 文件是问题,即使在高速WIFI连接上它似乎永无止境下载。几分钟后,有一个致命的例外。问题部分是循环(条件线)。
请一些提示?我错过了什么..
例外:
FATAL EXCEPTION: IntentService[DownloadService]
java.lang.OutOfMemoryError
at java.lang.String.<init>(String.java:432)
at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:642)
at java.lang.StringBuffer.toString(StringBuffer.java:723)
at com.splunk.mint.network.io.InputStreamMonitor.updateBody(InputStreamMonitor.java:123)
at com.splunk.mint.network.io.InputStreamMonitor.read(InputStreamMonitor.java:77)
at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:142)
at java.io.BufferedInputStream.read(BufferedInputStream.java:309)
at java.io.InputStream.read(InputStream.java:163)
at cz.ppmfactum.android_smartaudit.application.application.connection.DownloadService.download(DownloadService.java:103)
at cz.ppmfactum.android_smartaudit.application.application.connection.DownloadService.onHandleIntent(DownloadService.java:46)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
代码:
private synchronized void download(Intent intent) throws Exception {
String urlString = intent.getStringExtra("url");
Log.e("URL DOWNLOAD", urlString);
String path = intent.getStringExtra("path");
String name = intent.getStringExtra("name") + ".temp";
FileOutputStream output;
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
connection.connect();
InputStream input = new BufferedInputStream(url.openStream());
File rootFile = new File(path);
if (!rootFile.exists())
rootFile.mkdirs();
File outputFile = new File(rootFile, name);
if (outputFile.exists()) outputFile.delete();
output = new FileOutputStream(outputFile);
byte data[] = new byte[1024];
int count;
while ((count = input.read(data)) != -1) {
output.write(data, 0, count);
}
FileControler.renameFile(outputFile, intent.getStringExtra("name"));
downloadedFile = new File(outputFile.getParent(), intent.getStringExtra("name"));
output.flush();
output.close();
input.close();
}
答案 0 :(得分:0)
崩溃可能是由名为Mint的新BugSense库引起的......现在回过头来。
答案 1 :(得分:0)
我想告诉您,我们正在处理此问题,并且很快就会修复。现在你可以通过运行Mint.disableNetworkMonitoring()来禁用网络监控;就在init之前。谢谢你的报告!