android java not enough sequential memory for stringbuilder -


my app parsing large http response, http response on 6 megabytes , json, not in standard schema.

        final char[] buffer = new char[0x10000];         stringbuilder out = new stringbuilder();         reader in = new inputstreamreader(is, "utf-8");         int read;         system.gc();                 {             read = in.read(buffer, 0, buffer.length);             if (read > 0)             {                 out.append(buffer, 0, read);             }         } while (read >= 0);         in.close();         is.close();         in = null;         = null;         system.gc();         return out.tostring(); 

it doesn't matter if there bufferedreader file, or inputstream, stringbuilder cannot contain entire object , fails @ out.append(buffer, 0, read); or fail @ out.tostring() copy may made

ioutils.copy apache library doing same things under hood , fail.

how can read large object in further manipulation. right method fails on android 2.2 , 2.3 devices, , uses more memory want on newer devices.

similar questions have answers involve appending stringbuilder, reading in lines, or have incomplete solutions hints, , doesn't work.

you need 1 of 2 things:

  1. get multiple smaller json responses server , parse those. might preferable on mobile device, large chunks of data might not transmitted reliably, cause device request entire thing repeatedly.
  2. use streaming json parser, such jackson, process data comes in.

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -