summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2010-11-02 06:48:54 -0700
committerAndroid Code Review <code-review@android.com>2010-11-02 06:48:54 -0700
commit754b6b1317b1fa3a3fad69c1cbbecd22a2e99a06 (patch)
tree476815ec532cf78adc031ba073d55d4476c8cb7c
parent78d66fda7935a5af739d76eccee667d63e260137 (diff)
parent208b7834ee01388a5fecacf00a9c1e1b8ffc5240 (diff)
downloadMms-froyo-plus-aosp.tar.gz
Merge "Add support for chunked encoding when downloading MMS PDUs"tools_r9tools_r8froyo-plus-aosp
-rw-r--r--src/com/android/mms/transaction/HttpUtils.java34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/com/android/mms/transaction/HttpUtils.java b/src/com/android/mms/transaction/HttpUtils.java
index 9d734615..168803fe 100644
--- a/src/com/android/mms/transaction/HttpUtils.java
+++ b/src/com/android/mms/transaction/HttpUtils.java
@@ -39,7 +39,8 @@ import android.text.TextUtils;
import android.util.Config;
import android.util.Log;
-import java.io.DataInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
import java.io.IOException;
import java.net.SocketException;
import java.net.URI;
@@ -55,6 +56,8 @@ public class HttpUtils {
public static final int HTTP_POST_METHOD = 1;
public static final int HTTP_GET_METHOD = 2;
+ private static final int MMS_READ_BUFFER = 4096;
+
// This is the value to use for the "Accept-Language" header.
// Once it becomes possible for the user to change the locale
// setting, this should no longer be static. We should call
@@ -207,23 +210,26 @@ public class HttpUtils {
byte[] body = null;
if (entity != null) {
try {
- if (entity.getContentLength() > 0) {
- body = new byte[(int) entity.getContentLength()];
- DataInputStream dis = new DataInputStream(entity.getContent());
+ InputStream in = entity.getContent();
+ ByteArrayOutputStream out = new ByteArrayOutputStream(MMS_READ_BUFFER);
+ byte[] buffer = new byte[MMS_READ_BUFFER];
+
+ int byteCount;
+ try {
+ while ((byteCount = in.read(buffer)) != -1) {
+ out.write(buffer, 0, byteCount);
+ }
+ body = out.toByteArray();
+ } finally {
try {
- dis.readFully(body);
- } finally {
- try {
- dis.close();
- } catch (IOException e) {
- Log.e(TAG, "Error closing input stream: " + e.getMessage());
- }
+ in.close();
+ out.close();
+ } catch (IOException e) {
+ Log.e(TAG, "Error closing input stream: " + e.getMessage());
}
}
} finally {
- if (entity != null) {
- entity.consumeContent();
- }
+ entity.consumeContent();
}
}
return body;