java.io.IOException: BufferedInputStream is closed when downloading image file in android java -
i got hte following error
05-10 11:14:47.925: w/system.err(9681): java.io.ioexception: bufferedinputstream closed 05-10 11:14:47.925: w/system.err(9681): @ java.io.bufferedinputstream.streamclosed(bufferedinputstream.java:118) 05-10 11:14:47.925: w/system.err(9681): @ java.io.bufferedinputstream.available(bufferedinputstream.java:112) 05-10 11:14:47.925: w/system.err(9681): @ android.graphics.bitmapfactory.nativedecodestream(native method) 05-10 11:14:47.925: w/system.err(9681): @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:529) 05-10 11:14:47.925: w/system.err(9681): @ android.graphics.bitmapfactory.decodestream(bitmapfactory.java:601) 05-10 11:14:47.925: w/system.err(9681): @ com.laroche.newsmedia.getimagebitmap(newsmedia.java:132) 05-10 11:14:47.932: w/system.err(9681): @ com.laroche.news.getnewslistbycategoryid(news.java:113) 05-10 11:14:47.932: w/system.err(9681): @ com.laroche.mainactivity$getdatatask.doinbackground(mainactivity.java:112) 05-10 11:14:47.932: w/system.err(9681): @ com.laroche.mainactivity$getdatatask.doinbackground(mainactivity.java:1) 05-10 11:14:47.932: w/system.err(9681): @ android.os.asynctask$2.call(asynctask.java:287) 05-10 11:14:47.932: w/system.err(9681): @ java.util.concurrent.futuretask.run(futuretask.java:234) 05-10 11:14:47.932: w/system.err(9681): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 05-10 11:14:47.932: w/system.err(9681): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1080) 05-10 11:14:47.932: w/system.err(9681): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:573) 05-10 11:14:47.932: w/system.err(9681): @ java.lang.thread.run(thread.java:856) in line of code:
bufferedinputstream bufferedinputstream = null; bitmap bmp = null; string urlstring = "http://ma2too3a.com:8084/newsimages/"+imagename; try { bufferedinputstream = new bufferedinputstream(ws.openhttpconnection(urlstring)); bmp = bitmapfactory.decodestream(bufferedinputstream); saveimage(bmp,imagename,c); bufferedinputstream.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } where openhttpconnection() function :
public inputstream openhttpconnection(string urlstring) throws ioexception{ inputstream in = null; int respobse = -1; url url = new url(urlstring); urlconnection conn = url.openconnection(); if(!(conn instanceof httpurlconnection)) throw new ioexception("it's not http connection"); try{ httpurlconnection httpconn = (httpurlconnection) conn; httpconn.setallowuserinteraction(false); httpconn.setinstancefollowredirects(true); httpconn.setrequestmethod("get"); httpconn.connect(); respobse = httpconn.getresponsecode(); if(respobse == httpurlconnection.http_ok){ in= httpconn.getinputstream(); log.d("http connection","ok"); } }catch (ioexception e) { log.e("http error",e.tostring()); throw new ioexception(); } return in; }
you're ignoring possible null return openconnection() method. better allow method throw declared exceptions , not catch them internally.
Comments
Post a Comment