in httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java [397:469]
private String buildString() {
final StringBuilder sb = new StringBuilder();
if (this.scheme != null) {
sb.append(this.scheme).append(':');
}
if (this.encodedSchemeSpecificPart != null) {
sb.append(this.encodedSchemeSpecificPart);
} else {
final boolean authoritySpecified;
if (this.encodedAuthority != null) {
sb.append("//").append(this.encodedAuthority);
authoritySpecified = true;
} else if (this.host != null) {
sb.append("//");
if (this.encodedUserInfo != null) {
sb.append(this.encodedUserInfo).append("@");
} else if (this.userInfo != null) {
final int idx = this.userInfo.indexOf(':');
if (idx != -1) {
PercentCodec.encode(sb, this.userInfo.substring(0, idx), this.charset,
encodingPolicy == EncodingPolicy.ALL_RESERVED ? PercentCodec.UNRESERVED : PercentCodec.USERINFO, false);
sb.append(':');
PercentCodec.encode(sb, this.userInfo.substring(idx + 1), this.charset,
encodingPolicy == EncodingPolicy.ALL_RESERVED ? PercentCodec.UNRESERVED : PercentCodec.USERINFO, false);
} else {
PercentCodec.encode(sb, this.userInfo, this.charset,
encodingPolicy == EncodingPolicy.ALL_RESERVED ? PercentCodec.UNRESERVED : PercentCodec.USERINFO, false);
}
sb.append("@");
}
if (InetAddressUtils.isIPv6(this.host)) {
sb.append("[").append(this.host).append("]");
} else {
PercentCodec.encode(sb, this.host, this.charset,
encodingPolicy == EncodingPolicy.ALL_RESERVED ? PercentCodec.UNRESERVED : PercentCodec.REG_NAME, false);
}
if (this.port >= 0) {
sb.append(":").append(this.port);
}
authoritySpecified = true;
} else {
authoritySpecified = false;
}
if (this.encodedPath != null) {
if (authoritySpecified && !TextUtils.isEmpty(this.encodedPath) && !this.encodedPath.startsWith("/")) {
sb.append('/');
}
sb.append(this.encodedPath);
} else if (this.pathSegments != null) {
formatPath(sb, this.pathSegments, !authoritySpecified && this.pathRootless, this.charset,
encodingPolicy == EncodingPolicy.ALL_RESERVED ? PercentCodec.UNRESERVED : PercentCodec.PATH_SEGMENT);
}
if (this.encodedQuery != null) {
sb.append("?").append(this.encodedQuery);
} else if (this.queryParams != null && !this.queryParams.isEmpty()) {
sb.append("?");
formatQuery(sb, this.queryParams, this.charset,
encodingPolicy == EncodingPolicy.ALL_RESERVED ? PercentCodec.UNRESERVED : PercentCodec.QUERY, false);
} else if (this.query != null) {
sb.append("?");
PercentCodec.encode(sb, this.query, this.charset,
encodingPolicy == EncodingPolicy.ALL_RESERVED ? PercentCodec.URIC : PercentCodec.QUERY, false);
}
}
if (this.encodedFragment != null) {
sb.append("#").append(this.encodedFragment);
} else if (this.fragment != null) {
sb.append("#");
PercentCodec.encode(sb, this.fragment, this.charset,
encodingPolicy == EncodingPolicy.ALL_RESERVED ? PercentCodec.URIC : PercentCodec.FRAGMENT, false);
}
return sb.toString();
}