OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 package org.adblockplus.libadblockplus; | 18 package org.adblockplus.libadblockplus; |
19 | 19 |
20 import java.util.ArrayList; | 20 import java.util.ArrayList; |
21 import java.util.HashMap; | 21 import java.util.HashMap; |
22 import java.util.List; | 22 import java.util.List; |
23 | 23 |
24 import com.github.rjeschke.neetutils.collections.Tuple; | 24 import com.github.rjeschke.neetutils.collections.Tuple; |
25 | 25 |
26 public class ServerResponse | 26 public final class ServerResponse |
27 { | 27 { |
28 public static enum NsStatus | 28 public static enum NsStatus |
29 { | 29 { |
30 OK(0), ERROR_FAILURE(0x80004005), ERROR_OUT_OF_MEMORY(0x8007000e), ERROR_MAL
FORMED_URI(0x804b000a), ERROR_CONNECTION_REFUSED(0x804b000d), ERROR_NET_TIMEOUT( | 30 OK(0), ERROR_FAILURE(0x80004005), ERROR_OUT_OF_MEMORY(0x8007000e), ERROR_MAL
FORMED_URI(0x804b000a), ERROR_CONNECTION_REFUSED(0x804b000d), ERROR_NET_TIMEOUT( |
31 0x804b000e), ERROR_NO_CONTENT(0x804b0011), ERROR_UNKNOWN_PROTOCOL(0x804b
0012), ERROR_NET_RESET(0x804b0014), ERROR_UNKNOWN_HOST(0x804b001e), ERROR_REDIRE
CT_LOOP( | 31 0x804b000e), ERROR_NO_CONTENT(0x804b0011), ERROR_UNKNOWN_PROTOCOL(0x804b
0012), ERROR_NET_RESET(0x804b0014), ERROR_UNKNOWN_HOST(0x804b001e), ERROR_REDIRE
CT_LOOP( |
32 0x804b001f), ERROR_UNKNOWN_PROXY_HOST(0x804b002a), ERROR_NET_INTERRU
PT(0x804b0047), ERROR_UNKNOWN_PROXY_CONNECTION_REFUSED(0x804b0048), CUSTOM_ERROR
_BASE( | 32 0x804b001f), ERROR_UNKNOWN_PROXY_HOST(0x804b002a), ERROR_NET_INTERRU
PT(0x804b0047), ERROR_UNKNOWN_PROXY_CONNECTION_REFUSED(0x804b0048), CUSTOM_ERROR
_BASE( |
33 0x80850000), ERROR_NOT_INITIALIZED(0xc1f30001); | 33 0x80850000), ERROR_NOT_INITIALIZED(0xc1f30001); |
34 | 34 |
35 private final long statusCode; | 35 private final long statusCode; |
36 private final static HashMap<Long, NsStatus> ENUM_MAP = new HashMap<Long, Se
rverResponse.NsStatus>(); | 36 private final static HashMap<Long, NsStatus> ENUM_MAP = new HashMap<Long, Se
rverResponse.NsStatus>(); |
37 | 37 |
38 static | 38 static |
39 { | 39 { |
40 for (final NsStatus e : NsStatus.values()) | 40 for (final NsStatus e : NsStatus.values()) |
41 { | 41 { |
42 ENUM_MAP.put(e.statusCode, e); | 42 ENUM_MAP.put(e.statusCode, e); |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 private NsStatus(final long value) | 46 private NsStatus(final long value) |
47 { | 47 { |
48 statusCode = value; | 48 this.statusCode = value; |
49 } | 49 } |
50 | 50 |
51 public long getStatusCode() | 51 public long getStatusCode() |
52 { | 52 { |
53 return statusCode; | 53 return this.statusCode; |
54 } | 54 } |
55 | 55 |
56 public static NsStatus fromStatusCode(final long code) | 56 public static NsStatus fromStatusCode(final long code) |
57 { | 57 { |
58 final NsStatus status = ENUM_MAP.get(code); | 58 final NsStatus status = ENUM_MAP.get(code); |
59 return status != null ? status : ERROR_FAILURE; | 59 return status != null ? status : ERROR_FAILURE; |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 private long status = NsStatus.OK.getStatusCode(); | 63 private long status = NsStatus.OK.getStatusCode(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 int i = 0; | 125 int i = 0; |
126 for (final Tuple<String, String> e : headers) | 126 for (final Tuple<String, String> e : headers) |
127 { | 127 { |
128 this.headers[i] = e.a; | 128 this.headers[i] = e.a; |
129 this.headers[i + 1] = e.b; | 129 this.headers[i + 1] = e.b; |
130 i += 2; | 130 i += 2; |
131 } | 131 } |
132 } | 132 } |
133 } | 133 } |
134 } | 134 } |
OLD | NEW |