MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / setAuthority

Method setAuthority

vm/JavaAPI/src/java/net/URI.java:297–331  ·  view source on GitHub ↗

Utility method - set the part, ensuring valid format. If encode=true, then some elements will be run through the encoder (path, userinfo, query, fragment), otherwise the elements will be validated for proper encoding.

(String newAuthority, boolean encode)

Source from the content-addressed store, hash-verified

295 * encoding.
296 */
297 protected void setAuthority(String newAuthority, boolean encode) throws URISyntaxException {
298 if ((this.authority = newAuthority) == null) {
299 return;
300 }
301 if (authority.startsWith(AUTHORITY_MARKER)) {
302 authority = authority.substring(AUTHORITY_MARKER.length());
303 newAuthority = authority;
304 }
305 int index = newAuthority.indexOf(USERINFO_SEPARATOR);
306 if (index != -1) {
307 this.userInfo = newAuthority.substring(0, index);
308 if (encode) {
309 this.userInfo = URIHelper.encodeString(this.userInfo);
310 } else {
311 // validate
312 URIHelper.decodeString(this.userInfo);
313 }
314 newAuthority = newAuthority.substring(index + 1);
315 }
316 index = newAuthority.indexOf(PORT_SEPARATOR);
317 if (index == 0) {
318 this.host = null;
319 this.port = parseIntOption("port", newAuthority.substring(1));
320 } else if (index == -1) {
321 this.host = newAuthority;
322 this.port = -1;
323 } else {
324 this.host = newAuthority.substring(0, index);
325 this.port = parseIntOption("port", newAuthority.substring(index + 1));
326 }
327 if (encode == true) {
328 // to reconstruct the authority with the encoded value
329 setAuthority(host, port, userInfo, false);
330 }
331 }
332
333 /**
334 * Utility method to set the query. If parameter encode=true, then the

Callers 2

URIMethod · 0.95

Calls 9

encodeStringMethod · 0.95
decodeStringMethod · 0.95
parseIntOptionMethod · 0.95
appendMethod · 0.95
toStringMethod · 0.95
startsWithMethod · 0.65
substringMethod · 0.65
lengthMethod · 0.65
indexOfMethod · 0.65

Tested by

no test coverage detected