MCPcopy Create free account
hub / github.com/grpc/grpc-java / create

Method create

api/src/main/java/io/grpc/Uri.java:214–281  ·  view source on GitHub ↗

Creates a URI from a string assumed to be valid. Useful for defining URI constants in code. Not for user input. @throws IllegalArgumentException if 's' is not a valid RFC 3986 URI.

(String s)

Source from the content-addressed store, hash-verified

212 * @throws IllegalArgumentException if 's' is not a valid RFC 3986 URI.
213 */
214 public static Uri create(String s) {
215 Builder builder = new Builder();
216 int i = 0;
217 final int n = s.length();
218
219 // 3.1. Scheme: Look for a ':' before '/', '?', or '#'.
220 int schemeColon = -1;
221 for (; i < n; ++i) {
222 char c = s.charAt(i);
223 if (c == ':') {
224 schemeColon = i;
225 break;
226 } else if (c == '/' || c == '?' || c == '#') {
227 break;
228 }
229 }
230 if (schemeColon < 0) {
231 throw new IllegalArgumentException("Missing required scheme.");
232 }
233 builder.setRawScheme(s.substring(0, schemeColon));
234
235 // 3.2. Authority. Look for '//' then keep scanning until '/', '?', or '#'.
236 i = schemeColon + 1;
237 if (i + 1 < n && s.charAt(i) == '/' && s.charAt(i + 1) == '/') {
238 // "//" just means we have an authority. Skip over it.
239 i += 2;
240
241 int authorityStart = i;
242 for (; i < n; ++i) {
243 char c = s.charAt(i);
244 if (c == '/' || c == '?' || c == '#') {
245 break;
246 }
247 }
248 builder.setRawAuthority(s.substring(authorityStart, i));
249 }
250
251 // 3.3. Path: Whatever is left before '?' or '#'.
252 int pathStart = i;
253 for (; i < n; ++i) {
254 char c = s.charAt(i);
255 if (c == '?' || c == '#') {
256 break;
257 }
258 }
259 builder.setRawPath(s.substring(pathStart, i));
260
261 // 3.4. Query, if we stopped at '?'.
262 if (i < n && s.charAt(i) == '?') {
263 i++; // Skip '?'
264 int queryStart = i;
265 for (; i < n; ++i) {
266 char c = s.charAt(i);
267 if (c == '#') {
268 break;
269 }
270 }
271 builder.setRawQuery(s.substring(queryStart, i));

Callers 15

newNameResolverMethod · 0.95
newNameResolverMethod · 0.95
parse_emptyQueryMethod · 0.95
parse_emptyFragmentMethod · 0.95
parse_emptyUserInfoMethod · 0.95
parse_emptyPortMethod · 0.95
parse_emptyAuthorityMethod · 0.95

Calls 6

setRawSchemeMethod · 0.95
setRawAuthorityMethod · 0.95
setRawPathMethod · 0.95
setRawQueryMethod · 0.95
setRawFragmentMethod · 0.95
buildMethod · 0.95

Tested by 15

newNameResolverMethod · 0.76
newNameResolverMethod · 0.76
parse_emptyQueryMethod · 0.76
parse_emptyFragmentMethod · 0.76
parse_emptyUserInfoMethod · 0.76
parse_emptyPortMethod · 0.76
parse_emptyAuthorityMethod · 0.76