android - Is there a faster way to download a page from the net to a string? -


I have tried other ways to download information from a URL but need a fast one. I need to download and pars 250 different pages, and want that the app does not appear to be ridiculously slow. This code is currently being used to get a page, no insight would be great.

  try {url = myURL = new URL ("http://www.google.com"); URLConnection ucon = myURL.openConnection (); InputStream inputstream = ucon.getInputStream (); Buffetfindeinputstream buffedinputstream = new buffer inputtop (inputstream); Byterebrafer bytererefresh = new byterebarfter (50); Int current = 0; While ((current = bufferedInputStream.read ())! = -1) {byteArrayBuffer.append (byte)); } TempString = New String (ByterebarFoot.to Batteryre); } Hold (exception e) {Log.i ("error", estosting ()); }  

If the connections are on the same server then try to open the connection as well Try to avoid re-regulation in Buffer, and read as much as possible at a time.

  const int APPROX_MAX_PAGE_SIZE = 300; Try the {URL myURL = New URL ("http://www.google.com"); URLConnection ucon = myURL.openConnection (); Ucon.setRequestHeader ("Connection", "Keep-alive") // (1) InputStream inputstream = ucon.getInputStream (); Buffetfindeinputstream buffedinputstream = new buffer inputtop (inputstream); Byterebrator Bytererefour = New Byte Arraybreaker (APRX_MAX_ PAGE_SIZE); // (2) int current = 0; Byte [] buf = new byte [APPROX_MAX_PAGE_SIZE]; Read int; Do {read = bufferedInputStream.read (buf, 0, buf.length); // (3) if (read> 0) byterebarf.epend (buff, 0, read); } While (read> = 0); TempString = New String (ByterebarFoot.to Batteryre); } Hold (exception e) {Log.i ("error", estosting ());  
  1. Set up the set header (Not sure that you need it, it is also a configurable asset on J2SE)
  2. Allocate " Generally what is sufficiently "to avoid reallocation in the buffer.
  3. Read more than one byte at a time

Disclaimer: This is "Java in Java" compiler. It may be that the SEVIDER is available only on HTTPRQRCNNCNNCNNCND, or some parameters are wrong, but please do not hesitate to edit if so.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -