- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
<分区>
Possible Duplicate:
Android:“Unexpected end of stream” exception downloading large files
我正在下载一个大约的文件。 5MB 使用 HttpURLConnection 但在下载过程中途我在我的代码的这一行收到 “流的意外结束” 错误:
while ((count = input.read(data)) > 0) {
这是日志:
11-20 16:05:55.749: ERROR/PRINTSTACK(3425): STACK:unexpected end of stream
11-20 16:05:55.749: WARN/System.err(3425): java.io.IOException: unexpected end of stream
11-20 16:05:55.749: WARN/System.err(3425): at org.apache.harmony.luni.internal.net.www.protocol.http.FixedLengthInputStream.read(FixedLengthInputStream.java:47)
11-20 16:05:55.749: WARN/System.err(3425): at java.io.BufferedInputStream.read(BufferedInputStream.java:319)
11-20 16:05:55.749: WARN/System.err(3425): at java.io.FilterInputStream.read(FilterInputStream.java:133)
11-20 16:05:55.759: WARN/System.err(3425): at com.conjure.skiproj.DownloadService$Job.process(DownloadService.java:265)
11-20 16:05:55.759: WARN/System.err(3425): at com.conjure.skiproj.DownloadService$1.run(DownloadService.java:193)
11-20 16:05:55.759: WARN/System.err(3425): at java.lang.Thread.run(Thread.java:1019)
求助!!1
编辑:关于设置输入流的代码的更多信息:
HttpURLConnection conexion = (HttpURLConnection)url.openConnection();
conexion.setRequestMethod("GET");
conexion.setReadTimeout(20000);
conexion.connect();
File file = new File(root.getAbsolutePath()+"/", fileName);
int lenghtOfFile = conexion.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(file);
byte data[] = new byte[8192];
...........................
编辑 2:在以下行的 25% 下载中出现新错误 IndexOutOfBoundsException:
output.write(data, 0, count);
日志如下:
11-20 17:47:02.311: ERROR/totaltotal(303): 24
11-20 17:47:02.311: INFO/System.out(303): countcountcount:4332
11-20 17:47:02.330: ERROR/totaltotal(303): 24
11-20 17:47:02.330: INFO/System.out(303): countcountcount:2904
11-20 17:47:02.330: ERROR/totaltotal(303): 25
11-20 17:47:02.330: INFO/System.out(303): countcountcount:1452
11-20 17:47:02.330: ERROR/totaltotal(303): 25
11-20 17:47:02.650: INFO/System.out(303): countcountcount:4356
11-20 17:47:02.650: ERROR/totaltotal(303): 25
11-20 17:47:02.650: INFO/System.out(303): countcountcount:-1
11-20 17:47:02.660: ERROR/totaltotal(303): 25
11-20 17:47:02.892: DEBUG/dalvikvm(303): GC_FOR_MALLOC freed 10770 objects / 490896 bytes in 143ms
11-20 17:47:03.060: ERROR/PRINTSTACK(303): STACK:Arguments out of bounds
11-20 17:47:03.060: WARN/System.err(303): java.lang.IndexOutOfBoundsException: Arguments out of bounds
11-20 17:47:03.070: WARN/System.err(303): at java.io.FileOutputStream.write(FileOutputStream.java:288)
11-20 17:47:03.080: WARN/System.err(303): at com.conjure.skiproj.DownloadService$Job.process(DownloadService.java:275)
11-20 17:47:03.080: WARN/System.err(303): at com.conjure.skiproj.DownloadService$1.run(DownloadService.java:191)
11-20 17:47:03.080: WARN/System.err(303): at java.lang.Thread.run(Thread.java:1096)
编辑 3:我将错误追溯到 FixedLengthInputStream 类,然后进一步追溯到 AbstractHttpInputStream 类,其中有这个方法:
/**
* Calls abort on the cache entry and disconnects the socket. This
* should be invoked when the connection is closed unexpectedly to
* invalidate the cache entry and to prevent the HTTP connection from
* being reused. HTTP messages are sent in serial so whenever a message
* cannot be read to completion, subsequent messages cannot be read
* either and the connection must be discarded.
*
* <p>An earlier implementation skipped the remaining bytes, but this
* requires that the entire transfer be completed. If the intention was
* to cancel the transfer, closing the connection is the only solution.
*/
protected final void unexpectedEndOfInput() {
if (cacheRequest != null) {
cacheRequest.abort();
}
httpURLConnection.releaseSocket(false);
}
所以似乎在 Http 消息错误的情况下,整个下载流都被取消了。
我正在编写一个类,我想知道哪一对方法更适合描述流程周期: start() -> stop() start() -> end() start() -> finish() 基本上这些方法将在执行任务之前和
对于 Android 小部件类名称是否应以“View”、“Layout”或两者都不结尾,是否存在模式或命名约定? 最佳答案 如果该类扩展了 View(或在其层次结构中扩展了 View),那么它应该以“
我正在尝试找到一个插件,该插件将使用 Verilog 突出显示匹配的开始/结束语句。 VIM 让它与花括号/括号一起工作,但它不能与它的开始/结束一起工作。我希望 VIM 突出显示正确的开始到正确的结
给出以下代码: % Generate some random data n = 10; A = cell(n, 1); for i=1:n A{i} = timeseries; A{i
我需要知道是否可以检测输入何时开始聚焦以及何时结束焦点 HTML 代码: JQuery 代码(仅示例我如何需要它): $('.datas').on('focusStart', alert("fo
所以我一直在思考一款游戏的想法,一款需要穿越时空的游戏。因此,我编写了一个 JFrame 来显示螺旋的 .gif,但它并没有在对话框显示时结束,而是保留在后台。我可以解决这个问题吗? import j
给出以下使用多线程的 Java 示例: import java.util.concurrent.*; public class SquareCalculator { private Ex
好吧,我有一个 do-while 循环,应该在使用点击“q”时结束,但它给了我错误消息,请帮忙。 package Assignments; import java.util.*; public cla
我如何有选择地匹配开始 ^或结束 $正则表达式中的一行? 例如: /(?\\1', $str); 我的字符串开头和结尾处的粗体边缘情况没有被匹配。我在使用其他变体时遇到的一些极端情况包括字符串内匹配、
我试图让程序在总数达到 10 时结束,但由于某种原因,我的 while 循环在达到 10 时继续计数。一旦回答了 10 个问题,我就有 int 百分比来查找百分比。 import java.util.
jQuery 中的 end() 函数将元素集恢复到上次破坏性更改之前的状态,因此我可以看到它应该如何使用,但我已经看到了一些代码示例,例如:on alistapart (可能来自旧版本的 jQuery
这个问题在这里已经有了答案: How to check if a string "StartsWith" another string? (18 个答案) 关闭 9 年前。 var file =
我正在尝试在 travis 上设置两个数据库,但它只是在 before_install 声明的中途停止: (END) No output has been received in the last 1
我创建了一个简单的存储过程,它循环遍历一个表的行并将它们插入到另一个表中。由于某种原因,END WHILE 循环抛出缺少分号错误。所有代码对我来说都是正确的,并且所有分隔符都设置正确。我只是不明白为什
您好,我正在使用 AVSpeechSynthesizer 和 AVSpeechUtterance 构建一个 iOS 7 应用程序,我想弄清楚合成何时完成。更具体地说,我想在合成结束时更改播放/暂停按钮
这是我的代码,我试图在响应后显示警报。但没有显示操作系统警报 string filepath = ConfigurationManager.AppSettings["USPPath"].ToStri
我想创建一个循环,在提供的时间段、第一天和最后一天返回每个月(考虑到月份在第 28-31 天结束):(“function_to_increase_month”尚未定义) for beg in pd.d
我目前正在用 Python 3.6 为一个骰子游戏编写代码,我知道我的编码在这方面有点不对劲,但是,我真的只是想知道如何开始我的 while 循环。游戏说明如下…… 人类玩家与计算机对战。 玩家 1
所以我已经了解了如何打开 fragment。这是我的困境。我的 view 旁边有一个元素列表(元素周期表元素)。当您选择一个元素时,它会显示它的信息。 我的问题是我需要能够从(我们称之为详细信息 fr
我想检测用户何时停止滚动页面/元素。这可能很棘手,因为最近对 OSX 滚动行为的增强创造了这种新的惯性效应。是否触发了事件? 我能想到的唯一其他解决方案是在页面/元素的滚动位置不再改变时使用间隔来拾取
我是一名优秀的程序员,十分优秀!