224 return wildcard;
225 }
226
227 // these shouldn't leak outside the implementation
228 static final int[] HTTP_PORT = {80, 80};
229 static final int[] HTTPS_PORT = {443, 443};
230 static final int[] NO_PORT = {-1, -1};
231
232 int[] defaultPort() {
233 if (scheme.equals("http")) {
234 return HTTP_PORT;
235 } else if (scheme.equals("https")) {
236 return HTTPS_PORT;
237 }
238 return NO_PORT;
239 }
240
241 int[] parsePort(String port)
242 {
243
244 if (port == null || port.equals("")) {
245 return defaultPort();
246 }
247
248 if (port.equals("*")) {
249 return new int[] {PORT_MIN, PORT_MAX};
250 }
251
252 try {
253 int dash = port.indexOf('-');
254
255 if (dash == -1) {
256 int p = Integer.parseInt(port);
257 return new int[] {p, p};
258 } else {
259 String low = port.substring(0, dash);
260 String high = port.substring(dash+1);
261 int l,h;
262
263 if (low.equals("")) {
264 l = PORT_MIN;
265 } else {
266 l = Integer.parseInt(low);
267 }
268
269 if (high.equals("")) {
270 h = PORT_MAX;
271 } else {
272 h = Integer.parseInt(high);
273 }
274 if (l < 0 || h < 0 || h<l) {
275 return defaultPort();
276 }
277 return new int[] {l, h};
278 }
279 } catch (IllegalArgumentException e) {
280 return defaultPort();
281 }
282 }
283 }
|
224 return wildcard;
225 }
226
227 // these shouldn't leak outside the implementation
228 static final int[] HTTP_PORT = {80, 80};
229 static final int[] HTTPS_PORT = {443, 443};
230 static final int[] NO_PORT = {-1, -1};
231
232 int[] defaultPort() {
233 if (scheme.equals("http")) {
234 return HTTP_PORT;
235 } else if (scheme.equals("https")) {
236 return HTTPS_PORT;
237 }
238 return NO_PORT;
239 }
240
241 int[] parsePort(String port)
242 {
243
244 if (port == null || port.isEmpty()) {
245 return defaultPort();
246 }
247
248 if (port.equals("*")) {
249 return new int[] {PORT_MIN, PORT_MAX};
250 }
251
252 try {
253 int dash = port.indexOf('-');
254
255 if (dash == -1) {
256 int p = Integer.parseInt(port);
257 return new int[] {p, p};
258 } else {
259 String low = port.substring(0, dash);
260 String high = port.substring(dash+1);
261 int l,h;
262
263 if (low.isEmpty()) {
264 l = PORT_MIN;
265 } else {
266 l = Integer.parseInt(low);
267 }
268
269 if (high.isEmpty()) {
270 h = PORT_MAX;
271 } else {
272 h = Integer.parseInt(high);
273 }
274 if (l < 0 || h < 0 || h<l) {
275 return defaultPort();
276 }
277 return new int[] {l, h};
278 }
279 } catch (IllegalArgumentException e) {
280 return defaultPort();
281 }
282 }
283 }
|