1d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru/* 2d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * Copyright (C) 2011 The Android Open Source Project 3d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * 4d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * Licensed under the Apache License, Version 2.0 (the "License"); 5d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * you may not use this file except in compliance with the License. 6d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * You may obtain a copy of the License at 7d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * 8d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * http://www.apache.org/licenses/LICENSE-2.0 9d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * 10d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * Unless required by applicable law or agreed to in writing, software 11d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * distributed under the License is distributed on an "AS IS" BASIS, 12d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * See the License for the specific language governing permissions and 14d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * limitations under the License. 15d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru */ 16d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru 17d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Querupackage com.android.volley; 18d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru 19d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queruimport org.apache.http.HttpStatus; 20d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru 21d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queruimport java.util.Collections; 22d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queruimport java.util.Map; 23d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru 24d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru/** 25d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * Data and headers returned from {@link Network#performRequest(Request)}. 26d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru */ 27d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Querupublic class NetworkResponse { 28d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru /** 29d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * Creates a new network response. 30d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * @param statusCode the HTTP status code 31d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * @param data Response body 32d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * @param headers Headers returned with this response, or null for none 33d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru * @param notModified True if the server returned a 304 and the data was already in cache 34750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev * @param networkTimeMs Round-trip network time to receive network response 35d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru */ 36d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru public NetworkResponse(int statusCode, byte[] data, Map<String, String> headers, 37750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev boolean notModified, long networkTimeMs) { 38d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru this.statusCode = statusCode; 39d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru this.data = data; 40d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru this.headers = headers; 41d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru this.notModified = notModified; 42750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev this.networkTimeMs = networkTimeMs; 43750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev } 44750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev 45750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev public NetworkResponse(int statusCode, byte[] data, Map<String, String> headers, 46750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev boolean notModified) { 47750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev this(statusCode, data, headers, notModified, 0); 48d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru } 49d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru 50d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru public NetworkResponse(byte[] data) { 51750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev this(HttpStatus.SC_OK, data, Collections.<String, String>emptyMap(), false, 0); 52d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru } 53d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru 54e48f4430bfd3030350aa5ba827b449c37e2fadc9Jean-Baptiste Queru public NetworkResponse(byte[] data, Map<String, String> headers) { 55750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev this(HttpStatus.SC_OK, data, headers, false, 0); 56e48f4430bfd3030350aa5ba827b449c37e2fadc9Jean-Baptiste Queru } 57e48f4430bfd3030350aa5ba827b449c37e2fadc9Jean-Baptiste Queru 58d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru /** The HTTP status code. */ 59d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru public final int statusCode; 60d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru 61d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru /** Raw data from this response. */ 62d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru public final byte[] data; 63d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru 64d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru /** Response headers. */ 65d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru public final Map<String, String> headers; 66d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru 67d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru /** True if the server returned a 304 (Not Modified). */ 68d56b88ae161057e848e7410d1b9ce5b0b8c427fcJean-Baptiste Queru public final boolean notModified; 69750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev 70750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev /** Network roundtrip time in milliseconds. */ 71750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev public final long networkTimeMs; 72750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev} 73750c5b995f4f326c7b30ab88eda20b25285dd2f7Ivan Stalev 74