@Test public void testParseAuthority_noAuthority_3() { String input = "?key=value"; String authority = UriUtils.parseAuthority(input); String expectedAuthority = URI.create(input).getAuthority(); assertThat(input, authority, equalTo(expectedAuthority)); }
public static String parseAuthority(String uri) { if (uri == null) { return null; } int index = uri.indexOf(": if (index <= 0) { return null; } String schemeLess = uri.substring(index + 3); String authority; if (schemeLess.isEmpty()) { return null; } else { int beginningOfPath = schemeLess.indexOf("/"); int beginningOfQuery = schemeLess.indexOf("?"); int beginningOfFragment = schemeLess.indexOf("#"); if (beginningOfPath != -1) { authority = schemeLess.substring(0, beginningOfPath); } else if (beginningOfQuery != -1) { authority = schemeLess.substring(0, beginningOfQuery); } else if (beginningOfFragment != -1) { authority = schemeLess.substring(0, beginningOfFragment); } else { authority = schemeLess; } } return authority.isEmpty() ? null : authority; }
UriUtils { public static String parseAuthority(String uri) { if (uri == null) { return null; } int index = uri.indexOf(": if (index <= 0) { return null; } String schemeLess = uri.substring(index + 3); String authority; if (schemeLess.isEmpty()) { return null; } else { int beginningOfPath = schemeLess.indexOf("/"); int beginningOfQuery = schemeLess.indexOf("?"); int beginningOfFragment = schemeLess.indexOf("#"); if (beginningOfPath != -1) { authority = schemeLess.substring(0, beginningOfPath); } else if (beginningOfQuery != -1) { authority = schemeLess.substring(0, beginningOfQuery); } else if (beginningOfFragment != -1) { authority = schemeLess.substring(0, beginningOfFragment); } else { authority = schemeLess; } } return authority.isEmpty() ? null : authority; } }
UriUtils { public static String parseAuthority(String uri) { if (uri == null) { return null; } int index = uri.indexOf(": if (index <= 0) { return null; } String schemeLess = uri.substring(index + 3); String authority; if (schemeLess.isEmpty()) { return null; } else { int beginningOfPath = schemeLess.indexOf("/"); int beginningOfQuery = schemeLess.indexOf("?"); int beginningOfFragment = schemeLess.indexOf("#"); if (beginningOfPath != -1) { authority = schemeLess.substring(0, beginningOfPath); } else if (beginningOfQuery != -1) { authority = schemeLess.substring(0, beginningOfQuery); } else if (beginningOfFragment != -1) { authority = schemeLess.substring(0, beginningOfFragment); } else { authority = schemeLess; } } return authority.isEmpty() ? null : authority; } private  UriUtils(); }
UriUtils { public static String parseAuthority(String uri) { if (uri == null) { return null; } int index = uri.indexOf(": if (index <= 0) { return null; } String schemeLess = uri.substring(index + 3); String authority; if (schemeLess.isEmpty()) { return null; } else { int beginningOfPath = schemeLess.indexOf("/"); int beginningOfQuery = schemeLess.indexOf("?"); int beginningOfFragment = schemeLess.indexOf("#"); if (beginningOfPath != -1) { authority = schemeLess.substring(0, beginningOfPath); } else if (beginningOfQuery != -1) { authority = schemeLess.substring(0, beginningOfQuery); } else if (beginningOfFragment != -1) { authority = schemeLess.substring(0, beginningOfFragment); } else { authority = schemeLess; } } return authority.isEmpty() ? null : authority; } private  UriUtils(); static List<String> parseSegments(String uri); static List<InetSocketAddress> parseInetSocketAddresses(String uri); static List<InetSocketAddress> parseInetSocketAddresses(String uri, int defaultPort); static String parseScheme(String uri); static String parseAuthority(String uri); static String parseUserInfo(String uri); static String parsePath(String uri); static String parseQuery(String uri); static String appendSegmentToPath(String path, String segment); }
UriUtils { public static String parseAuthority(String uri) { if (uri == null) { return null; } int index = uri.indexOf(": if (index <= 0) { return null; } String schemeLess = uri.substring(index + 3); String authority; if (schemeLess.isEmpty()) { return null; } else { int beginningOfPath = schemeLess.indexOf("/"); int beginningOfQuery = schemeLess.indexOf("?"); int beginningOfFragment = schemeLess.indexOf("#"); if (beginningOfPath != -1) { authority = schemeLess.substring(0, beginningOfPath); } else if (beginningOfQuery != -1) { authority = schemeLess.substring(0, beginningOfQuery); } else if (beginningOfFragment != -1) { authority = schemeLess.substring(0, beginningOfFragment); } else { authority = schemeLess; } } return authority.isEmpty() ? null : authority; } private  UriUtils(); static List<String> parseSegments(String uri); static List<InetSocketAddress> parseInetSocketAddresses(String uri); static List<InetSocketAddress> parseInetSocketAddresses(String uri, int defaultPort); static String parseScheme(String uri); static String parseAuthority(String uri); static String parseUserInfo(String uri); static String parsePath(String uri); static String parseQuery(String uri); static String appendSegmentToPath(String path, String segment);  }