相关疑难解决方法(0)

java.net.ProtocolException:意外的流结束

我面临一个奇怪的问题,我无法调试它.我已经实现用于上载的数据的流,并且正在使用排球对于相同的逻辑,我已经定制的逻辑点点HurlStack,addBodyIfExistsAPI,所以类型"application /八位字节流"的该机构可以处理.

我的逻辑是将进度发布给用户,以便可以更新UI,指示用户在上传中的进度,低于我的逻辑.

            int toRead = length; // File length
            byte[] data = new byte[4096];
            connection.setDoOutput(true);
            if(length != -1) {
                connection.setFixedLengthStreamingMode(length);
            } else {
                connection.setChunkedStreamingMode(4096);
            }

            OutputStream os;
            int i;
            int count;

            os = connection.getOutputStream();
            int progress= 0;

               try {
                    for(i = 0; (count= is.read(data)) > 0; ++i) { // is, is not null and contains a valid input stream
                        os.write(data, 0, count); // at this line am getting unexpected end of stream
                        progress+= count;
                        if(i …
Run Code Online (Sandbox Code Playgroud)

android android-volley okhttp

10
推荐指数
1
解决办法
2万
查看次数

Android:"意外的流结束"异常下载大文件

我正在构建一个Android应用程序,我需要从一个大小为33 MB的URL下载文件.

这里的下载任务:

try {
            int MAX_BUFFER_SIZE = 4096;
            URL mUrl = new URL(params[0]);
            HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection();
            connection.setRequestMethod("GET");
            long length = connection.getContentLength(), downloaded = 0;
            int read;
            byte [] buffer = new byte[(((int)length) > MAX_BUFFER_SIZE) ? MAX_BUFFER_SIZE : (int)length];
            String filename = getFilename(mUrl);
            File file = new File (SDCARD_ROOT);
            if (!file.exists() || !file.isDirectory()){
                file.mkdir();
            }
            this.filename = filename;
            file = new File (SDCARD_ROOT + this.filename);  
            FileOutputStream fos = new FileOutputStream (file);
            //Start downloading
            InputStream stream = connection.getInputStream();

            while …
Run Code Online (Sandbox Code Playgroud)

java android inputstream download

6
推荐指数
1
解决办法
9722
查看次数

VideoView Stream加载不够缓冲

我的Android应用程序在线播放视频VideoView.从文件播放视频时,它可以正常工作,甚至可以直播(a m3u8); 它总是来自同一个源,当我使用外部播放器/浏览器时,它同样流畅(所以我不认为这是源的问题,这是这样的文件的变体:https:/ /publish.dvlabs.com/democracynow/360/dn2016-0810.mp4

Android Monitor在崩溃之前记录这个:

10-13 12:02:56.204 32460-32748/com.workingagenda.democracydroid D/MediaHTTPConnection: filterOutInternalHeaders: key=User-Agent, val= stagefright/1.2 (Linux;Android 6.0.1)
10-13 12:02:56.205 32460-32472/com.workingagenda.democracydroid D/MediaHTTPConnection: proxy null port 0
10-13 12:02:57.904 32460-32460/com.workingagenda.democracydroid D/MediaPlayer: getMetadata
10-13 12:02:58.438 32460-377/com.workingagenda.democracydroid W/MediaPlayer: info/warning (3, 0)
Run Code Online (Sandbox Code Playgroud)

然后我崩溃时得到这些日志:

10-13 12:05:33.812 32460-32472/com.workingagenda.democracydroid W/MediaHTTPConnection: readAt 26869519 / 241 => java.net.ProtocolException: unexpected end of stream
10-13 12:08:32.480 32460-3546/com.workingagenda.democracydroid E/MediaPlayer: error (1, -1004)
10-13 12:08:32.480 32460-32460/com.workingagenda.democracydroid E/MediaPlayer: Error (1,-1004)
10-13 12:08:32.481 32460-32460/com.workingagenda.democracydroid D/VideoView: Error: 1,-1004

                                                                         [ 10-13 12:08:32.512  5066:  453 E/ …
Run Code Online (Sandbox Code Playgroud)

android stream android-mediaplayer android-videoview

5
推荐指数
1
解决办法
1622
查看次数