我正在使用改造库从服务器下载apk文件。 我收到 OutofmemoryException ,因为它的8 MB文件。
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): at retrofit.Utils.readBodyToBytesIfNecessary(Utils.java:81)
06-04 17:02:36.252: I/dalvikvm(32227): at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:348)
06-04 17:02:36.252: I/dalvikvm(32227): at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:240)
06-04 17:02:36.252: I/dalvikvm(32227): at $Proxy0.getApkFile(Native Method)
我的代码:
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();
}