retomar reanudar reanuda play interrumpidas incompleta google descargas descarga crdownload continuar con chrome cancelada java android http download

java - interrumpidas - reanudar descarga play store



Cómo reanudar una descarga interrumpida-Parte 2 (3)

Esta es una continuación de mi pregunta anterior que publiqué cuando no era un usuario registrado. Como una actualización, estoy tratando de reanudar la descarga de un archivo grande de mi Yahoo! servidor de sitio web cuando se interrumpe la descarga. Anteriormente pensé que la interrupción se debía a un límite de tiempo de espera de 100 segundos (porque Yahoo! aplica ese límite en los scripts escritos por el usuario). Sin embargo, cuando medí el tiempo de las interrupciones de la descarga, vi que la sincronización de la interrupción varía mucho (a veces la descarga se ejecuta sin interrupciones durante menos de 100 segundos y, a veces, hasta siete minutos). Así que no sé la razón de los tiempos de espera y estoy tratando de evitarlos.

Intenté la sugerencia de naikus (gracias) y, según el volcado de los campos del encabezado http, parece que mi Yahoo! el servidor del sitio web reconoce la propiedad "rango" que debería permitir que la descarga se reanude en el desplazamiento de la interrupción. Desafortunadamente, aunque el rango de bytes aparece correcto en el encabezado http en las conexiones reanudadas, el contenido transferido siempre se reinicia al principio del archivo. (Mi archivo de prueba es una matriz de 50,000 enteros de 4 bytes que se incrementan a partir de 0. Mi archivo descargado siempre comienza a contar a 0 en cada desplazamiento en el que ocurrió una interrupción de la descarga).

¿Hay alguna otra solicitud de propiedad de conexión http que debería hacer para obtener el Yahoo! ¿El servidor realmente saltará al desplazamiento de archivo especificado en el rango de bytes del encabezado? Aquí está el código y lo que vuelca:

// Setup connection. URL url = new URL(strUrl[0]); URLConnection connection = url.openConnection(); downloaded = Integer.parseInt(strUrl[3]); if (downloaded > 0) { connection.setRequestProperty("Range", "bytes="+downloaded+"-"); connection.connect(); fileLength = mDownloadFileLength; Log.d("AsyncDownloadFile", "new download seek: " + downloaded + "; lengthFile: " + fileLength); } else { connection.connect(); downloaded = 0; fileLength = connection.getContentLength(); mDownloadFileLength = fileLength; } Map<String, List<String>> map = connection.getHeaderFields(); Log.d("AsyncDownloadFile", "header fields: " + map.toString()); // Setup streams and buffers. input = new BufferedInputStream(url.openStream(), 8192); outFile = new RandomAccessFile(strUrl[1], "rw"); if (downloaded > 0) outFile.seek(downloaded); byte data[] = new byte[1024]; // Download file. for (int count=0, i=0; (count=input.read(data, 0, 1024)) != -1; i++) { outFile.write(data, 0, count); downloaded += count; if (downloaded >= fileLength) break; // Display progress. Log.d("AsyncDownloadFile", "bytes: " + downloaded); if ((i%10) == 0) publishProgress((int)(downloaded*100/fileLength)); if (mFlagDisableAsyncTask) { downloaded = 0; break; } } // Close streams. outFile.close(); input.close();

tugurio:

@ 4:08:24 D/AsyncDownloadFile( 2372): header fields: {p3p=[policyref="http://info.yahoo.co m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA PO L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-mo dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[2000000], age=[0], serve r=[YTS/1.17.13], accept-ranges=[bytes], date=[Fri, 06 Aug 2010 20:08:33 GMT]} D/AsyncDownloadFile( 2372): bytes: 1024 D/AsyncDownloadFile( 2372): bytes: 1033 D/AsyncDownloadFile( 2372): bytes: 2057 D/AsyncDownloadFile( 2372): bytes: 2493 D/AsyncDownloadFile( 2372): bytes: 3517 D/AsyncDownloadFile( 2372): bytes: 3953 . . . @ 4:13:25 D/AsyncDownloadFile( 2372): bytes: 386473 D/AsyncDownloadFile( 2372): bytes: 387497 D/AsyncDownloadFile( 2372): bytes: 387933 D/AsyncDownloadFile( 2372): new download seek: 387933; lengthFile: 2000000 D/AsyncDownloadFile( 2372): header fields: {p3p=[policyref="http://info.yahoo.co m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA PO L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-mo dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[1612067], age=[0], serve r=[YTS/1.17.13], accept-ranges=[bytes], date=[Fri, 06 Aug 2010 20:13:29 GMT], co ntent-range=[bytes 387933-1999999/2000000]} D/AsyncDownloadFile( 2372): bytes: 388957 D/AsyncDownloadFile( 2372): bytes: 389981 D/AsyncDownloadFile( 2372): bytes: 390409 D/AsyncDownloadFile( 2372): bytes: 391433 D/AsyncDownloadFile( 2372): bytes: 391869 D/AsyncDownloadFile( 2372): bytes: 392893 . . . @ 4:18:45 D/AsyncDownloadFile( 2372): bytes: 775413 D/AsyncDownloadFile( 2372): bytes: 775849 D/AsyncDownloadFile( 2372): bytes: 776873 D/AsyncDownloadFile( 2372): bytes: 777309 D/AsyncDownloadFile( 2372): new download seek: 777309; lengthFile: 2000000 D/AsyncDownloadFile( 2372): header fields: {p3p=[policyref="http://info.yahoo.co m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA PO L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-mo dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[1222691], age=[0], serve r=[YTS/1.17.13], accept-ranges=[bytes], date=[Fri, 06 Aug 2010 20:18:54 GMT], co ntent-range=[bytes 777309-1999999/2000000]} D/dalvikvm( 2372): GC_FOR_MALLOC freed 11019 objects / 470560 bytes in 155ms D/AsyncDownloadFile( 2372): bytes: 778333 D/AsyncDownloadFile( 2372): bytes: 779357 D/AsyncDownloadFile( 2372): bytes: 779790 D/AsyncDownloadFile( 2372): bytes: 780814 D/AsyncDownloadFile( 2372): bytes: 781250 D/AsyncDownloadFile( 2372): bytes: 782274 . . . @ 4:23:45 D/AsyncDownloadFile( 2372): bytes: 1163334 D/AsyncDownloadFile( 2372): bytes: 1163770 D/AsyncDownloadFile( 2372): bytes: 1164794 D/AsyncDownloadFile( 2372): bytes: 1165230 D/AsyncDownloadFile( 2372): new download seek: 1165230; lengthFile: 2000000 D/AsyncDownloadFile( 2372): header fields: {p3p=[policyref="http://info.yahoo.co m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA PO L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-mo dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[834770], age=[0], server =[YTS/1.17.13], accept-ranges=[bytes], date=[Fri, 06 Aug 2010 20:23:47 GMT], con tent-range=[bytes 1165230-1999999/2000000]} D/AsyncDownloadFile( 2372): bytes: 1166246 D/AsyncDownloadFile( 2372): bytes: 1167270 D/AsyncDownloadFile( 2372): bytes: 1167706 D/AsyncDownloadFile( 2372): bytes: 1168730 D/AsyncDownloadFile( 2372): bytes: 1169754 D/AsyncDownloadFile( 2372): bytes: 1170778 . . . @ 4:30:25 D/AsyncDownloadFile( 2372): bytes: 1551255 D/AsyncDownloadFile( 2372): bytes: 1551691 D/AsyncDownloadFile( 2372): bytes: 1552715 D/AsyncDownloadFile( 2372): bytes: 1553151 D/AsyncDownloadFile( 2372): new download seek: 1553151; lengthFile: 2000000 D/AsyncDownloadFile( 2372): header fields: {p3p=[policyref="http://info.yahoo.co m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA PO L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-mo dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[446849], age=[0], server =[YTS/1.17.13], accept-ranges=[bytes], date=[Fri, 06 Aug 2010 20:30:44 GMT], con tent-range=[bytes 1553151-1999999/2000000]} D/AsyncDownloadFile( 2372): bytes: 1554167 D/AsyncDownloadFile( 2372): bytes: 1554184 D/AsyncDownloadFile( 2372): bytes: 1555208 D/AsyncDownloadFile( 2372): bytes: 1555644 D/AsyncDownloadFile( 2372): bytes: 1556668 D/AsyncDownloadFile( 2372): bytes: 1557104 . . . @ 4:37:10 D/AsyncDownloadFile( 2372): bytes: 1939188 D/AsyncDownloadFile( 2372): bytes: 1939624 D/AsyncDownloadFile( 2372): bytes: 1940648 D/AsyncDownloadFile( 2372): bytes: 1941084 D/AsyncDownloadFile( 2372): new download seek: 1941084; lengthFile: 2000000 D/dalvikvm( 2372): GC_FOR_MALLOC freed 13701 objects / 604600 bytes in 128ms D/AsyncDownloadFile( 2372): header fields: {p3p=[policyref="http://info.yahoo.co m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA PO L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-mo dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[58916], age=[0], server= [YTS/1.17.13], accept-ranges=[bytes], date=[Fri, 06 Aug 2010 20:37:16 GMT], cont ent-range=[bytes 1941084-1999999/2000000]} D/AsyncDownloadFile( 2372): bytes: 1942108 D/AsyncDownloadFile( 2372): bytes: 1942117 D/AsyncDownloadFile( 2372): bytes: 1943141 D/AsyncDownloadFile( 2372): bytes: 1943577 D/AsyncDownloadFile( 2372): bytes: 1944601 D/AsyncDownloadFile( 2372): bytes: 1945037 . . . @ 4:38:30 D/AsyncDownloadFile( 2372): bytes: 1993217 D/AsyncDownloadFile( 2372): bytes: 1994241 D/AsyncDownloadFile( 2372): bytes: 1994677 D/AsyncDownloadFile( 2372): bytes: 1995701 D/AsyncDownloadFile( 2372): bytes: 1996137 D/AsyncDownloadFile( 2372): bytes: 1997161 D/AsyncDownloadFile( 2372): bytes: 1997597 D/AsyncDownloadFile( 2372): bytes: 1998621 D/AsyncDownloadFile( 2372): bytes: 1999057 D/onPostExecute( 2372): download: unsuccessful - - -

Después de la sugerencia de BalusC (gracias), modifiqué la configuración de la conexión pero Yahoo! El servidor continúa restableciendo el inicio del archivo en cada interrupción. Aquí está el código modificado y los volcados resultantes:

// Setup connection. URL url = new URL(strUrl[0]); URLConnection connection = url.openConnection(); downloaded = Integer.parseInt(strUrl[3]); if (downloaded == 0) { connection.connect(); strLastModified = connection.getHeaderField("Last-Modified"); fileLength = connection.getContentLength(); mDownloadFileLength = fileLength; } else { connection.setRequestProperty("Range", "bytes=" + downloaded + "-"); connection.setRequestProperty("If-Range", strLastModified); connection.connect(); fileLength = mDownloadFileLength; Log.d("AsyncDownloadFile", "new download seek: " + downloaded + "; lengthFile: " + fileLength); } map = connection.getHeaderFields(); Log.d("AsyncDownloadFile", "header fields: " + map.toString());

tugurio:

@12:36:40 started D/AsyncDownloadFile( 413): header fields: {p3p=[policyref="http://info.yahoo.c m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTP OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA P L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-m dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[2000000], age=[0], serv r=[YTS/1.17.13], accept-ranges=[bytes], date=[Sat, 07 Aug 2010 04:36:56 GMT]} D/AsyncDownloadFile( 413): bytes: 1024 D/AsyncDownloadFile( 413): bytes: 2048 D/AsyncDownloadFile( 413): bytes: 2476 D/AsyncDownloadFile( 413): bytes: 3500 D/AsyncDownloadFile( 413): bytes: 3936 ... @12:39:20 interrupted D/AsyncDownloadFile( 413): bytes: 388068 D/AsyncDownloadFile( 413): bytes: 389092 D/AsyncDownloadFile( 413): bytes: 389376 D/AsyncDownloadFile( 413): new download seek: 389376; lengthFile: 2000000 D/AsyncDownloadFile( 413): header fields: {p3p=[policyref="http://info.yahoo.co m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA PO L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-mo dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[1610624], age=[0], serve r=[YTS/1.17.13], accept-ranges=[bytes], date=[Sat, 07 Aug 2010 04:39:21 GMT], co ntent-range=[bytes 389376-1999999/2000000]} D/AsyncDownloadFile( 413): bytes: 390400 D/AsyncDownloadFile( 413): bytes: 390409 D/AsyncDownloadFile( 413): bytes: 391433 D/AsyncDownloadFile( 413): bytes: 391869 ... @12:44:10 interrupted D/AsyncDownloadFile( 413): bytes: 775413 D/AsyncDownloadFile( 413): bytes: 775849 D/AsyncDownloadFile( 413): bytes: 776873 D/AsyncDownloadFile( 413): bytes: 777309 D/AsyncDownloadFile( 413): new download seek: 777309; lengthFile: 2000000 D/AsyncDownloadFile( 413): header fields: {p3p=[policyref="http://info.yahoo.co m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA PO L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-mo dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[1222691], age=[0], serve r=[YTS/1.17.13], accept-ranges=[bytes], date=[Sat, 07 Aug 2010 04:44:20 GMT], co ntent-range=[bytes 777309-1999999/2000000]} D/dalvikvm( 413): GC_FOR_MALLOC freed 10869 objects / 465664 bytes in 122ms D/AsyncDownloadFile( 413): bytes: 778333 D/AsyncDownloadFile( 413): bytes: 778342 D/AsyncDownloadFile( 413): bytes: 779366 D/AsyncDownloadFile( 413): bytes: 779802 ... @12:49:30 interrupted D/AsyncDownloadFile( 413): bytes: 1163782 D/AsyncDownloadFile( 413): bytes: 1164806 D/AsyncDownloadFile( 413): bytes: 1165242 D/AsyncDownloadFile( 413): new download seek: 1165242; lengthFile: 2000000 D/AsyncDownloadFile( 413): header fields: {p3p=[policyref="http://info.yahoo.co m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA PO L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-mo dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[834758], age=[0], server =[YTS/1.17.13], accept-ranges=[bytes], date=[Sat, 07 Aug 2010 04:49:43 GMT], con tent-range=[bytes 1165242-1999999/2000000]} D/AsyncDownloadFile( 413): bytes: 1166266 D/AsyncDownloadFile( 413): bytes: 1167290 D/AsyncDownloadFile( 413): bytes: 1167718 D/AsyncDownloadFile( 413): bytes: 1168742 ... @12:55:30 interrupted D/AsyncDownloadFile( 413): bytes: 1552722 D/AsyncDownloadFile( 413): bytes: 1553158 D/AsyncDownloadFile( 413): bytes: 1554182 D/AsyncDownloadFile( 413): bytes: 1554618 D/AsyncDownloadFile( 413): new download seek: 1554618; lengthFile: 2000000 D/AsyncDownloadFile( 413): header fields: {p3p=[policyref="http://info.yahoo.co m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA PO L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-mo dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[445382], age=[0], server =[YTS/1.17.13], accept-ranges=[bytes], date=[Sat, 07 Aug 2010 04:55:39 GMT], con tent-range=[bytes 1554618-1999999/2000000]} D/AsyncDownloadFile( 413): bytes: 1555642 D/AsyncDownloadFile( 413): bytes: 1556666 D/AsyncDownloadFile( 413): bytes: 1557094 D/AsyncDownloadFile( 413): bytes: 1558118 ... @12:57:20 interrupted D/AsyncDownloadFile( 413): bytes: 1941834 D/AsyncDownloadFile( 413): bytes: 1942858 D/AsyncDownloadFile( 413): bytes: 1943882 D/AsyncDownloadFile( 413): bytes: 1943994 D/AsyncDownloadFile( 413): new download seek: 1943994; lengthFile: 2000000 D/AsyncDownloadFile( 413): header fields: {p3p=[policyref="http://info.yahoo.co m/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA PO L HEA PRE LOC GOV"], content-type=[application/zip], connection=[close], last-mo dified=[Fri, 06 Aug 2010 14:47:50 GMT], content-length=[56006], age=[0], server= [YTS/1.17.13], accept-ranges=[bytes], date=[Sat, 07 Aug 2010 04:57:15 GMT], cont ent-range=[bytes 1943994-1999999/2000000]} D/dalvikvm( 413): GC_FOR_MALLOC freed 13617 objects / 602200 bytes in 165ms D/AsyncDownloadFile( 413): bytes: 1945018 D/AsyncDownloadFile( 413): bytes: 1946042 D/AsyncDownloadFile( 413): bytes: 1946470 D/AsyncDownloadFile( 413): bytes: 1947494 ... @12:58:10 finished D/AsyncDownloadFile( 413): bytes: 1996103 D/AsyncDownloadFile( 413): bytes: 1997127 D/AsyncDownloadFile( 413): bytes: 1997563 D/AsyncDownloadFile( 413): bytes: 1998587 D/AsyncDownloadFile( 413): bytes: 1999023 D/onPostExecute( 413): downloaded: unsuccessful


Logré implementar la descarga de reanudar http en mi aplicación Java de cliente, el truco consistía en usar el encabezado de solicitud "If-Range: original_ETag" como se menciona en una respuesta aceptada. Aquí hay una información completa de depuración del encabezado que puede ayudarlo a comprender cómo funciona el currículum.

Respuesta normal del servidor, el archivo se lee desde el principio hasta el final. El valor de ETag es W / "filesize_bytes-modified_utc" metadatos del archivo de disco. Podría ser otra cosa, pero eso es lo que utiliza Tomcat y, por lo general, es mejor para el contenido de archivos normales.

HTTP/1.1 200 OK ETag: W/"19097900-1410863319978" Last-Modified: Tue, 16 Sep 2014 10:28:39 GMT Content-Length: 19097900 Content-Type: application/octet-stream Accept-Ranges: bytes Server: Apache-Coyote/1.1 Date: Wed, 17 Sep 2014 10:39:52 GMT

El cliente lee un fragmento dado del archivo agregando los encabezados Rango e If-Range. El rango de bytes puede estar abierto, por lo que el servidor debe leer desde el índice dado hasta el final. Note Content-Length no es la longitud total del archivo sino esta porción de bytes.

Range: bytes=10000000- If-Range: W/"19097900-1410863319978" HTTP/1.1 206 Partial Content ETag: W/"19097900-1410863319978" Last-Modified: Tue, 16 Sep 2014 10:28:39 GMT Content-Length: 9097900 Content-Type: application/octet-stream Accept-Ranges: bytes Content-Range: bytes 10000000-19097899/19097900 Server: Apache-Coyote/1.1 Date: Wed, 17 Sep 2014 18:12:36 GMT

Si se modificó el archivo remoto, el servidor no debería devolver 206-PartialContent sino una respuesta regular de 200-OK. El servidor debe usar el valor If-Range para verificar la consistencia. Algunos clientes, como VLCPlayer, ponen el campo Rango sin el valor If-Range.

Cuando el cliente realiza una solicitud inicial sin rango + encabezados If-Range, puede agregar el encabezado "If-Modified-Since: modified_http_date". El servidor puede devolver el estado 304-NotModified y el cliente está listo. Si el cliente proporciona byteStartIdx> = filesize, el servidor devuelve 416-RequestedRangeNotSatisfiable.

Volcados de depuración adicionales para aclarar cómo funciona http-resume.

Range=bytes=0-0 If-Range=W/"19097900-1410863319978" HTTP/1.1 206 Partial Content ETag=W/"19097900-1410863319978" Date=Fri, 19 Sep 2014 12:53:36 GMT Content-Length=1 Last-Modified=Tue, 16 Sep 2014 10:28:39 GMT Content-Type=application/octet-stream Accept-Ranges=bytes Server=Apache-Coyote/1.1 Content-Range=bytes 0-0/19097900 - - - - - Range=bytes=19097800-29097800 If-Range=W/"19097900-1410863319978" HTTP/1.1 206 Partial Content ETag=W/"19097900-1410863319978" Date=Fri, 19 Sep 2014 12:59:24 GMT Content-Length=100 Last-Modified=Tue, 16 Sep 2014 10:28:39 GMT Content-Type=application/octet-stream Accept-Ranges=bytes Server=Apache-Coyote/1.1 Content-Range=bytes 19097800-19097899/19097900 - - - - - - - - Range=bytes=19097899-19097899 If-Range=W/"19097900-1410863319978" HTTP/1.1 206 Partial Content ETag=W/"19097900-1410863319978" Date=Fri, 19 Sep 2014 13:01:47 GMT Content-Length=1 Last-Modified=Tue, 16 Sep 2014 10:28:39 GMT Content-Type=application/octet-stream Accept-Ranges=bytes Server=Apache-Coyote/1.1 Content-Range=bytes 19097899-19097899/19097900


Para reanudar una descarga, debe enviar no solo el encabezado de solicitud de Range , sino también el encabezado de solicitud de If-Range respuesta que debe contener el identificador de archivo único o la marca de tiempo de modificación de archivo.

Si el servidor devuelve un ETag respuesta ETag en la descarga inicial, entonces debe usarlo en el encabezado If-Range de las solicitudes de reanudación posteriores. O si devuelve un encabezado de respuesta de Last-Modified , entonces debería usarlo en el encabezado de solicitud If-Range .

En cuanto a sus registros, el servidor ha enviado un encabezado de respuesta de Last-Modified . Por lo tanto, debe enviarlo de vuelta en un encabezado If-Range de la solicitud de reanudación.

// Initial download. String lastModified = connection.getHeaderField("Last-Modified"); // ... // Resume download. connection.setRequestProperty("If-Range", lastModified);

El servidor utilizará esta información para verificar si está solicitando exactamente el mismo archivo.


Parece que el problema está llamando

input = new BufferedInputStream(url.openStream(), 8192);

en lugar de

input = new BufferedInputStream(connection.getInputStream(), 8192);

url.openStream() realiza otra llamada a openConnection() SIN la propiedad range.