Use the Eofexception workaround that appears in Universal-image-loader

Source: Internet
Author: User

Direct Sticker Code

public class Httpclientimagedownloader extends Baseimagedownloader implementsimagedownloader {public Httpclientimagedownloader (Context context) {super (context);} @Overrideprotected inputstream getstreamfromfile (string Imageuri, Object extra) throws IOException {string FilePath = Scheme.FILE.crop (Imageuri); File File = new file (FilePath), if (!file.exists ()) File.createnewfile (), return new Contentlengthinputstream (new Bufferedinputstream (New FileInputStream (FilePath), buffer_size), (int) new File (FilePath). Length ()); @SuppressLint ("usevalueof") @Overrideprotected inputstream getstreamfromnetwork (String Imageuri, Object extra) throws IOException {//httpurlconnection conn = createconnection (Imageuri, extra);////int Redirectcount = 0;//while ( Conn.getresponsecode ()/+ = 3 && Redirectcount < Max_redirect_count) {//conn = CreateConnection (conn.gethe Aderfield ("location"), extra);//redirectcount++;//}<span style= "font-family:arial, Helvetica, Sans-serif;" >//eofexception from Conn.getrEsponsecode () </span>//inputstream imagestream;//try {//imagestream = Conn.getinputstream ();/} catch ( IOException e) {////Read all data to allow reuse connection (Http://bit.ly/1ad35PY)//ioutils.readandclosestream ( Conn.geterrorstream ());//throw e;//}defaulthttpclient client = new Defaulthttpclient (); HttpGet request = new HttpGet (Imageuri); Request.getparams (). Setparameter ("Http.socket.timeout", New Integer ( ConnectTimeout) Request.addheader ("Pragma", "No-cache"), Request.addheader ("Cache-control", "No-cache"); Request.addheader ("Charset", "UTF-8"); HttpResponse HttpResponse = client.execute (request); httpentity entity = httpresponse.getentity (); InputStream ImageStream = Entity.getcontent (); return new Contentlengthinputstream (New Bufferedinputstream (ImageStream, buffer_size), (int) entity.getcontentlength ());}}
Additionally configured for own Imageloader
imageloaderconfiguration config = new Imageloaderconfiguration.builder (Getapplicationcontext ()). Defaultdisplayimageoptions (defaultoptions). ThreadPriority (thread.norm_priority-2). Denycacheimagemultiplesizesinmemory (). ThreadPoolSize (3). Imagedownloader (New Httpclientimagedownloader (this)). Tasksprocessingorder (Queueprocessingtype.lifo). MemoryCache (New Weakmemorycache ()). build ();


Use the Eofexception workaround that appears in Universal-image-loader

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.