I am using a modified library to download the apk file from the server. I get an Outofmemory Exception from my 8 MB file.
06-04 17: 02: 36.242: I / dalvikvm (32227): "AsyncTask # 1" prio = 5 tid = 12 RUNNABLE 06-04 17: 02: 36.242: I / dalvikvm (32227): | group = "main" sCount = 0 dsCount = 0 obj = 0x40fc7eb8 self = 0x2a1096a8 06-04 17: 02: 36.242: I / dalvikvm (32227): | sysTid = 32247 nice = 10 sched = 0/0 cgrp = apps / bg_non_interactive handle = 705879936 06-04 17: 02: 36.242: I / dalvikvm (32227): | schedstat = (1325450565 1518168555 7526) utm = 87 stm = 45 core = 0 06-04 17: 02: 36.242: I / dalvikvm (32227): at java.io.ByteArrayOutputStream.expand (ByteArrayOutputStream.java:~91) 06- 04 17: 02: 36.242: I / dalvikvm (32227): at java.io.ByteArrayOutputStream.write (ByteArrayOutputStream.java:201) 06-04 17: 02: 36.242: I / dalvikvm (32227): at retrofit.Utils. streamToBytes (Utils.java:44) 06-04 17: 02: 36.252: I / dalvikvm (32227): in retrofit.Utils.readBodyToBytesIfNecessary (Utils.java:81) 06-04 17: 02: 36.252: I / dalvikvm ( 32227): in retrofit.RestAdapter $ RestHandler.invokeRequest (RestAdapter.javahaps48) 06-04 17: 02: 36.252: I / dalvikvm (32227): in retrofit.RestAdapter $ RestHandler.invoke (RestAdapter.java:240) 06 -04 17: 02: 36.252: I / dalvikvm (32227): at $ Proxy0.getApkFile (native method)
My code is:
RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(url).setLogLevel(RestAdapter.LogLevel.HEADERS) .build(); //restAdapter.setLogLevel(RestAdapter.LogLevel.NONE); TypedByteArray bytearray=((TypedByteArray)restAdapter.create(ApkDownloadInterface.class).getApkFile().getBody()); try { Log.i("", "length "+bytearray.length()); BufferedInputStream bis=new BufferedInputStream(bytearray.in()); BufferedOutputStream bos=new BufferedOutputStream(fos); byte array[]=new byte[1024]; int x=0; while((x=bis.read(array))!=-1){ //Log.i("", "transferring data"); bos.write(array, 0, x); } bos.close(); bis.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
source share