Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/org/adblockplus/libadblockplus/ServerResponse.java

Issue 6606493159784448: New JNI bindings (Closed)
Left Patch Set: Created March 14, 2014, 11:32 a.m.
Right Patch Set: Removed TODO from AppInfo. Created April 11, 2014, 1:28 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/org/adblockplus/libadblockplus/LogSystem.java ('k') | src/org/adblockplus/libadblockplus/Subscription.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 package org.adblockplus.libadblockplus;
19
20 import java.util.ArrayList;
21 import java.util.HashMap;
22 import java.util.List;
23
24 import com.github.rjeschke.neetutils.collections.Tuple;
25
26 public class ServerResponse
27 {
28 public static enum NsStatus
29 {
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(
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);
34
35 private final long statusCode;
36 private final static HashMap<Long, NsStatus> ENUM_MAP = new HashMap<Long, Se rverResponse.NsStatus>();
37
38 static
39 {
40 for (final NsStatus e : NsStatus.values())
41 {
42 ENUM_MAP.put(e.statusCode, e);
43 }
44 }
45
46 private NsStatus(final long value)
47 {
48 statusCode = value;
49 }
50
51 public long getStatusCode()
52 {
53 return statusCode;
54 }
55
56 public static NsStatus fromStatusCode(final long code)
57 {
58 final NsStatus status = ENUM_MAP.get(code);
59 return status != null ? status : ERROR_FAILURE;
60 }
61 }
62
63 private long status = NsStatus.OK.getStatusCode();
64 private int responseStatus = 400;
65 private String[] headers = null;
66 // TODO: This (and the whole downloading) is a waste of memory, change String
67 // to something more suitable
68 private String response = null;
69
70 public NsStatus getStatus()
71 {
72 return NsStatus.fromStatusCode(this.status);
73 }
74
75 public void setStatus(final NsStatus status)
76 {
77 this.status = status.getStatusCode();
78 }
79
80 public int getResponseStatus()
81 {
82 return this.responseStatus;
83 }
84
85 public void setResponseStatus(final int status)
86 {
87 this.responseStatus = status;
88 }
89
90 public String getResponse()
91 {
92 return this.response;
93 }
94
95 public void setResponse(final String response)
96 {
97 this.response = response;
98 }
99
100 public List<Tuple<String, String>> getResponseHeaders()
101 {
102 final ArrayList<Tuple<String, String>> ret = new ArrayList<Tuple<String, Str ing>>();
103
104 if (this.headers != null)
105 {
106 for (int i = 0; i < this.headers.length; i += 2)
107 {
108 ret.add(Tuple.of(this.headers[i], this.headers[i + 1]));
109 }
110 }
111
112 return ret;
113 }
114
115 public void setReponseHeaders(final List<Tuple<String, String>> headers)
116 {
117 if (headers.isEmpty())
118 {
119 this.headers = null;
120 }
121 else
122 {
123 this.headers = new String[headers.size() * 2];
124
125 int i = 0;
126 for (final Tuple<String, String> e : headers)
127 {
128 this.headers[i] = e.a;
129 this.headers[i + 1] = e.b;
130 i += 2;
131 }
132 }
133 }
134 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld