src/share/classes/java/net/URI.java

Print this page




1812     {
1813         if (host != null) {
1814             sb.append("//");
1815             if (userInfo != null) {
1816                 sb.append(quote(userInfo, L_USERINFO, H_USERINFO));
1817                 sb.append('@');
1818             }
1819             boolean needBrackets = ((host.indexOf(':') >= 0)
1820                                     && !host.startsWith("[")
1821                                     && !host.endsWith("]"));
1822             if (needBrackets) sb.append('[');
1823             sb.append(host);
1824             if (needBrackets) sb.append(']');
1825             if (port != -1) {
1826                 sb.append(':');
1827                 sb.append(port);
1828             }
1829         } else if (authority != null) {
1830             sb.append("//");
1831             if (authority.startsWith("[")) {

1832                 int end = authority.indexOf("]");
1833                 if (end != -1 && authority.indexOf(":")!=-1) {
1834                     String doquote, dontquote;

1835                     if (end == authority.length()) {
1836                         dontquote = authority;
1837                         doquote = "";
1838                     } else {
1839                         dontquote = authority.substring(0,end+1);
1840                         doquote = authority.substring(end+1);
1841                     }
1842                     sb.append (dontquote);

1843                     sb.append(quote(doquote,
1844                             L_REG_NAME | L_SERVER,
1845                             H_REG_NAME | H_SERVER));
1846                 }
1847             } else {
1848                 sb.append(quote(authority,
1849                             L_REG_NAME | L_SERVER,
1850                             H_REG_NAME | H_SERVER));
1851             }
1852         }
1853     }
1854 
1855     private void appendSchemeSpecificPart(StringBuffer sb,
1856                                           String opaquePart,
1857                                           String authority,
1858                                           String userInfo,
1859                                           String host,
1860                                           int port,
1861                                           String path,
1862                                           String query)
1863     {
1864         if (opaquePart != null) {
1865             /* check if SSP begins with an IPv6 address
1866              * because we must not quote a literal IPv6 address




1812     {
1813         if (host != null) {
1814             sb.append("//");
1815             if (userInfo != null) {
1816                 sb.append(quote(userInfo, L_USERINFO, H_USERINFO));
1817                 sb.append('@');
1818             }
1819             boolean needBrackets = ((host.indexOf(':') >= 0)
1820                                     && !host.startsWith("[")
1821                                     && !host.endsWith("]"));
1822             if (needBrackets) sb.append('[');
1823             sb.append(host);
1824             if (needBrackets) sb.append(']');
1825             if (port != -1) {
1826                 sb.append(':');
1827                 sb.append(port);
1828             }
1829         } else if (authority != null) {
1830             sb.append("//");
1831             if (authority.startsWith("[")) {
1832                 // authority should (but may not) contain an embedded IPv6 address
1833                 int end = authority.indexOf("]");
1834                 String doquote = authority, dontquote = "";
1835                 if (end != -1 && authority.indexOf(":") != -1) {
1836                     // the authority contains an IPv6 address
1837                     if (end == authority.length()) {
1838                         dontquote = authority;
1839                         doquote = "";
1840                     } else {
1841                         dontquote = authority.substring(0 , end + 1);
1842                         doquote = authority.substring(end + 1);
1843                     }
1844                 }
1845                 sb.append(dontquote);
1846                 sb.append(quote(doquote,
1847                             L_REG_NAME | L_SERVER,
1848                             H_REG_NAME | H_SERVER));

1849             } else {
1850                 sb.append(quote(authority,
1851                             L_REG_NAME | L_SERVER,
1852                             H_REG_NAME | H_SERVER));
1853             }
1854         }
1855     }
1856 
1857     private void appendSchemeSpecificPart(StringBuffer sb,
1858                                           String opaquePart,
1859                                           String authority,
1860                                           String userInfo,
1861                                           String host,
1862                                           int port,
1863                                           String path,
1864                                           String query)
1865     {
1866         if (opaquePart != null) {
1867             /* check if SSP begins with an IPv6 address
1868              * because we must not quote a literal IPv6 address