开发者

Error in InputSreamReader with Http Connection

I am extening "AsyncTask" in class and running below code in run method using timer class its a continue task.

 HttpClient client = new DefaultHttpClient();
 HttpPost httpPost = new HttpPost(sche.URL);
 long startTime = System.currentTimeMillis();
 HttpResponse response = client.execute(httpPost);
 in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
 String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
 File file = new File(extStorageDirectory+"/"+runInBackend.count+sche.file_name);
 **is=new InputStreamReader(response.getEntity().getContent());**
 long bytesRead = 0;
 long totalBytesRead 
 //long startTime = System.currentTimeMillis();

 while ((bytesRead = is.read())!=0) 
 {    开发者_StackOverflow
     totalBytesRead += bytesRead;
 }

it is printing the below Output in logCat lines continuously but when i remove

InputStreamReader line that is bolded its work fine can anyone why this is behaving

like this

03-30 12:34:01.001: DEBUG/dalvikvm(862): GC freed 6389 objects / 256392 bytes in 151ms
03-30 12:34:01.561: DEBUG/dalvikvm(862): GC freed 18546 objects / 1005008 bytes in 172ms
03-30 12:34:02.001: DEBUG/dalvikvm(862): GC freed 16351 objects / 524352 bytes in 121ms
03-30 12:34:02.470: DEBUG/dalvikvm(862): GC freed 16347 objects / 524208 bytes in 164ms
03-30 12:34:02.910: DEBUG/dalvikvm(862): GC freed 16348 objects / 524264 bytes in 119ms
03-30 12:34:03.400: DEBUG/dalvikvm(862): GC freed 16351 objects / 524352 bytes in 162ms
03-30 12:34:03.841: DEBUG/dalvikvm(862): GC freed 16347 objects / 524192 bytes in 126ms
03-30 12:34:04.390: DEBUG/dalvikvm(862): GC freed 16348 objects / 524264 bytes in 224ms
03-30 12:34:04.840: DEBUG/dalvikvm(862): GC freed 16348 objects / 524256 bytes in 128ms
03-30 12:34:05.341: DEBUG/dalvikvm(862): GC freed 16351 objects / 524344 bytes in 171ms
03-30 12:34:05.791: DEBUG/dalvikvm(862): GC freed 16347 objects / 524224 bytes in 121ms
03-30 12:34:06.280: DEBUG/dalvikvm(862): GC freed 16351 objects / 524344 bytes in 164ms
03-30 12:34:06.721: DEBUG/dalvikvm(862): GC freed 16347 objects / 524200 bytes in 125ms
03-30 12:34:07.181: DEBUG/dalvikvm(862): GC freed 16350 objects / 524288 bytes in 156ms


Use org.apache.http.util.EntityUtils.toByteArray(final HttpEntity entity) to read byte array from the server response.

Another point - read it only once. In your code it looks like you are trying to do this twice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜