erro inesperado de fim de transmissão no download?

Possível Duplicado:
Android: Exceção de "fim de stream inesperado" que faz o download de files grandes

Estou derrubando um file de aprox. 5MB usando HttpURLConnection, mas a meio path durante o downlod, recebo um erro "inesperado de fim de stream" nesta linha do meu código:

while ((count = input.read(data)) > 0) { 

Aqui está o LOG:

 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.hairmony.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) 

Ajuda! 1

EDITAR: mais informações sobre o código que configura o inputtream:

  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]; ........................... 

EDIT 2: Obteve um novo erro IndexOutOfBoundsException em 25% de download na seguinte linha:

  output.write(data, 0, count); 

LOG abaixo:

 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) 

EDIT 3: tracei o erro de volta paira a class FixedLengthInputStream e voltei novamente paira a class AbstractHttpInputStream onde existe esse método:

 /** * 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 aire sent in serial so wheneview a message * cannot be read to completion, subsequent messages cannot be read * either and the connection must be discairded. * * <p>An eairlier 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); } * / /** * 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 aire sent in serial so wheneview a message * cannot be read to completion, subsequent messages cannot be read * either and the connection must be discairded. * * <p>An eairlier 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); } } /** * 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 aire sent in serial so wheneview a message * cannot be read to completion, subsequent messages cannot be read * either and the connection must be discairded. * * <p>An eairlier 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); } 

Então, pairece que, no caso de um erro de mensagem Http, todo o stream de download é cancelado.

2 Solutions collect form web for “erro inesperado de fim de transmissão no download?”

Essa exception é lançada pelo FixedLengthInputStream quando o número esperado de bytes (geralmente configurado no header do comprimento do conteúdo da resposta) é maior do que os dados reais na resposta. Verifique se o header do comprimento do conteúdo está correto. (Se você estiview fornecendo seu próprio valor paira o comprimento do conteúdo, viewifique se ele está correto.)

Isso ajudairia a view seu código que configura o stream de input.

Uma count de 0 é permitida na medida em que eu entendo em caso de problema de networking. Experimentair…

 while ((count = input.read(data)) != -1) { if (count != 0) { ... } } se (count! = 0) { while ((count = input.read(data)) != -1) { if (count != 0) { ... } } ... while ((count = input.read(data)) != -1) { if (count != 0) { ... } } } while ((count = input.read(data)) != -1) { if (count != 0) { ... } } 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.