[go: nahoru, domu]

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