最后一个字节失败的部分范围请求

partial range request with last byte failure

在尝试使用 chrome 作为视频播放工具来满足部分范围请求时,视频播放开始播放,但播放到一半时,它会冻结,就好像客户端仍在等待更多数据一样。此时服务器已经发送了整个请求。请注意以下请求和响应以及用于发送请求范围的代码:

Range:bytes=0-

Accept-Ranges:bytes
Content-Length:546827
Content-Range:bytes 0-546827/546828
Content-Type:video/webm

Accept-Ranges:bytes
Content-Length:6155
Content-Range:bytes 540672-546827/546828
Content-Type:video/webm


Accept-Ranges:bytes
Content-Length:1
Content-Range:bytes 546827-546827/546828
Content-Type:video/webm

第二个响应是否正确处理?导致它在此请求上冻结并再次开始发出多个请求,直到请求超时。

处理请求的代码:

private static void copyStream (PullBufferStream inputStream, OutputStream outputStream, BytesStreamObject bytesWrittenObj, int from, int to) throws IOException, CodecNotAvailableException {
    //export media stream
    BufferedOutputStream bout = new BufferedOutputStream (outputStream);
    Buffer b = new Buffer();
    long skipped =0;
    int byteLength = 0;

    do {
        inputStream.read(b);

        int len    = b.getLength();
        byte[] data   = (byte[]) b.getData();
        int  offset = b.getOffset();
        if (len > 0) {
            if(skipped < from) {             
              // skip bytes until reach from position in inputstream
              if(skipped + len <= from) {     
                  // skip all bytes just read
                  skipped += len;
              } else {                       
                  // skip only some of bytes read 
                  offset += (from - skipped);
                  len -= (from - skipped);
                  skipped = from;

              }
            } 
            if(to >= 0) {
                if(from + byteLength + len <= to) {
                    // use the full buffer
                } else {
                    // trim len to needed bytes to be read to prevent exceeding the "to" input parameter
                    len = (to + 1) - (from + byteLength);
                }
            } 

            byteLength+= len;
            bytesWrittenObj.bytesWritten = byteLength;
            bout.write(data, offset, len);
            //bout.write(data, from, end);
        } 
    } while (!b.isEOM());
    //fileProperties.setBytesLength(byteLength);

    //bout.close(); 

}

我需要确保刷新输出流,但也对实际文件大小做了一些更改,而不是使用 stream.available()。