Move EasResponse to top level class.

All behavior unmodified.

This prepares the way for some additional error codes (that aren't
necessarily HTTP error codes, since no connection can even be made) that
will be put on the EasResponse itself.

Change-Id: I1ba3b212dc63fb2f10a6462466e8fe62409b87e9
diff --git a/src/com/android/exchange/EasResponse.java b/src/com/android/exchange/EasResponse.java
new file mode 100644
index 0000000..a63c2c0
--- /dev/null
+++ b/src/com/android/exchange/EasResponse.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2008-2009 Marc Blank
+ * Licensed to The Android Open Source Project.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.exchange;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * Encapsulate a response to an HTTP POST
+ */
+public class EasResponse {
+    final HttpResponse mResponse;
+    private final HttpEntity mEntity;
+    private final int mLength;
+    private InputStream mInputStream;
+    private boolean mClosed;
+
+    public EasResponse(HttpResponse response) {
+        mResponse = response;
+        mEntity = mResponse.getEntity();
+        if (mEntity !=  null) {
+            mLength = (int)mEntity.getContentLength();
+        } else {
+            mLength = 0;
+        }
+    }
+
+    /**
+     * Return an appropriate input stream for the response, either a GZIPInputStream, for
+     * compressed data, or a generic InputStream otherwise
+     * @return the input stream for the response
+     */
+    public InputStream getInputStream() {
+        if (mInputStream != null || mClosed) {
+            throw new IllegalStateException("Can't reuse stream or get closed stream");
+        } else if (mEntity == null) {
+            throw new IllegalStateException("Can't get input stream without entity");
+        }
+        InputStream is = null;
+        try {
+            // Get the default input stream for the entity
+            is = mEntity.getContent();
+            Header ceHeader = mResponse.getFirstHeader("Content-Encoding");
+            if (ceHeader != null) {
+                String encoding = ceHeader.getValue();
+                // If we're gzip encoded, wrap appropriately
+                if (encoding.toLowerCase().equals("gzip")) {
+                    is = new GZIPInputStream(is);
+                }
+            }
+        } catch (IllegalStateException e1) {
+        } catch (IOException e1) {
+        }
+        mInputStream = is;
+        return is;
+    }
+
+    public boolean isEmpty() {
+        return mLength == 0;
+    }
+
+    public int getStatus() {
+        return mResponse.getStatusLine().getStatusCode();
+    }
+
+    public Header getHeader(String name) {
+        return mResponse.getFirstHeader(name);
+    }
+
+    public int getLength() {
+        return mLength;
+    }
+
+    public void close() {
+        if (mEntity != null && !mClosed) {
+            try {
+                mEntity.consumeContent();
+            } catch (IOException e) {
+                // No harm, no foul
+            }
+        }
+        mClosed = true;
+    }
+}
\ No newline at end of file
diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java
index 78bd632..16f3031 100644
--- a/src/com/android/exchange/EasSyncService.java
+++ b/src/com/android/exchange/EasSyncService.java
@@ -103,7 +103,6 @@
 import java.security.cert.CertificateException;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.zip.GZIPInputStream;
 
 public class EasSyncService extends AbstractSyncService {
     // DO NOT CHECK IN SET TO TRUE
@@ -447,84 +446,6 @@
         return svc;
     }
 
-    /**
-     * Encapsulate a response to an HTTP POST
-     */
-    public static class EasResponse {
-        private final HttpResponse mResponse;
-        private final HttpEntity mEntity;
-        private final int mLength;
-        private InputStream mInputStream;
-        private boolean mClosed;
-
-        public EasResponse(HttpResponse response) {
-            mResponse = response;
-            mEntity = mResponse.getEntity();
-            if (mEntity !=  null) {
-                mLength = (int)mEntity.getContentLength();
-            } else {
-                mLength = 0;
-            }
-        }
-
-        /**
-         * Return an appropriate input stream for the response, either a GZIPInputStream, for
-         * compressed data, or a generic InputStream otherwise
-         * @return the input stream for the response
-         */
-        public InputStream getInputStream() {
-            if (mInputStream != null || mClosed) {
-                throw new IllegalStateException("Can't reuse stream or get closed stream");
-            } else if (mEntity == null) {
-                throw new IllegalStateException("Can't get input stream without entity");
-            }
-            InputStream is = null;
-            try {
-                // Get the default input stream for the entity
-                is = mEntity.getContent();
-                Header ceHeader = mResponse.getFirstHeader("Content-Encoding");
-                if (ceHeader != null) {
-                    String encoding = ceHeader.getValue();
-                    // If we're gzip encoded, wrap appropriately
-                    if (encoding.toLowerCase().equals("gzip")) {
-                        is = new GZIPInputStream(is);
-                    }
-                }
-            } catch (IllegalStateException e1) {
-            } catch (IOException e1) {
-            }
-            mInputStream = is;
-            return is;
-        }
-
-        public boolean isEmpty() {
-            return mLength == 0;
-        }
-
-        public int getStatus() {
-            return mResponse.getStatusLine().getStatusCode();
-        }
-
-        public Header getHeader(String name) {
-            return mResponse.getFirstHeader(name);
-        }
-
-        public int getLength() {
-            return mLength;
-        }
-
-        public void close() {
-            if (mEntity != null && !mClosed) {
-                try {
-                    mEntity.consumeContent();
-                } catch (IOException e) {
-                    // No harm, no foul
-                }
-            }
-            mClosed = true;
-        }
-    }
-
     public static int searchMessages(Context context, long accountId, SearchParams searchParams,
             long destMailboxId) {
         // Sanity check for arguments
diff --git a/src/com/android/exchange/adapter/AttachmentLoader.java b/src/com/android/exchange/adapter/AttachmentLoader.java
index 7472799..c262df1 100644
--- a/src/com/android/exchange/adapter/AttachmentLoader.java
+++ b/src/com/android/exchange/adapter/AttachmentLoader.java
@@ -21,8 +21,8 @@
 import com.android.emailcommon.service.EmailServiceStatus;
 import com.android.emailcommon.utility.AttachmentUtilities;
 import com.android.exchange.Eas;
+import com.android.exchange.EasResponse;
 import com.android.exchange.EasSyncService;
-import com.android.exchange.EasSyncService.EasResponse;
 import com.android.exchange.ExchangeService;
 import com.android.exchange.PartRequest;
 
diff --git a/src/com/android/exchange/adapter/EmailSyncAdapter.java b/src/com/android/exchange/adapter/EmailSyncAdapter.java
index 5304b47..2e962bb 100644
--- a/src/com/android/exchange/adapter/EmailSyncAdapter.java
+++ b/src/com/android/exchange/adapter/EmailSyncAdapter.java
@@ -39,8 +39,8 @@
 import com.android.emailcommon.utility.Utility;
 import com.android.exchange.CommandStatusException;
 import com.android.exchange.Eas;
+import com.android.exchange.EasResponse;
 import com.android.exchange.EasSyncService;
-import com.android.exchange.EasSyncService.EasResponse;
 import com.android.exchange.MessageMoveRequest;
 import com.android.exchange.R;
 import com.android.exchange.utility.CalendarUtilities;
@@ -101,14 +101,14 @@
     private static final int LAST_VERB_REPLY_ALL = 2;
     private static final int LAST_VERB_FORWARD = 3;
 
-    private String[] mBindArguments = new String[2];
-    private String[] mBindArgument = new String[1];
+    private final String[] mBindArguments = new String[2];
+    private final String[] mBindArgument = new String[1];
 
     @VisibleForTesting
     ArrayList<Long> mDeletedIdList = new ArrayList<Long>();
     @VisibleForTesting
     ArrayList<Long> mUpdatedIdList = new ArrayList<Long>();
-    private ArrayList<FetchRequest> mFetchRequestList = new ArrayList<FetchRequest>();
+    private final ArrayList<FetchRequest> mFetchRequestList = new ArrayList<FetchRequest>();
     private boolean mFetchNeeded = false;
 
     // Holds the parser's value for isLooping()
@@ -430,12 +430,12 @@
         private static final String WHERE_SERVER_ID_AND_MAILBOX_KEY =
             SyncColumns.SERVER_ID + "=? and " + MessageColumns.MAILBOX_KEY + "=?";
 
-        private String mMailboxIdAsString;
+        private final String mMailboxIdAsString;
 
-        private ArrayList<Message> newEmails = new ArrayList<Message>();
-        private ArrayList<Message> fetchedEmails = new ArrayList<Message>();
-        private ArrayList<Long> deletedEmails = new ArrayList<Long>();
-        private ArrayList<ServerChange> changedEmails = new ArrayList<ServerChange>();
+        private final ArrayList<Message> newEmails = new ArrayList<Message>();
+        private final ArrayList<Message> fetchedEmails = new ArrayList<Message>();
+        private final ArrayList<Long> deletedEmails = new ArrayList<Long>();
+        private final ArrayList<ServerChange> changedEmails = new ArrayList<ServerChange>();
 
         public EasEmailSyncParser(InputStream in, EmailSyncAdapter adapter) throws IOException {
             super(in, adapter);