< prev index next >

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

Print this page




 486  * @since 1.4
 487  *
 488  * @see <a href="http://www.ietf.org/rfc/rfc2279.txt"><i>RFC&nbsp;2279: UTF-8, a
 489  * transformation format of ISO 10646</i></a>, <br><a
 490  * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC&nbsp;2373: IPv6 Addressing
 491  * Architecture</i></a>, <br><a
 492  * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC&nbsp;2396: Uniform
 493  * Resource Identifiers (URI): Generic Syntax</i></a>, <br><a
 494  * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC&nbsp;2732: Format for
 495  * Literal IPv6 Addresses in URLs</i></a>, <br><a
 496  * href="URISyntaxException.html">URISyntaxException</a>
 497  */
 498 
 499 public final class URI
 500     implements Comparable<URI>, Serializable
 501 {
 502 
 503     // Note: Comments containing the word "ASSERT" indicate places where a
 504     // throw of an InternalError should be replaced by an appropriate assertion
 505     // statement once asserts are enabled in the build.
 506 
 507     static final long serialVersionUID = -6052424284110960213L;
 508 
 509 
 510     // -- Properties and components of this instance --
 511 
 512     // Components of all URIs: [<scheme>:]<scheme-specific-part>[#<fragment>]
 513     private transient String scheme;            // null ==> relative URI
 514     private transient String fragment;
 515 
 516     // Hierarchical URI components: [//<authority>]<path>[?<query>]
 517     private transient String authority;         // Registry or server
 518 
 519     // Server-based authority: [<userInfo>@]<host>[:<port>]
 520     private transient String userInfo;
 521     private transient String host;              // null ==> registry-based
 522     private transient int port = -1;            // -1 ==> undefined
 523 
 524     // Remaining components of hierarchical URIs
 525     private transient String path;              // null ==> opaque
 526     private transient String query;


1760      *          charset
1761      */
1762     public String toASCIIString() {
1763         return encode(toString());
1764     }
1765 
1766 
1767     // -- Serialization support --
1768 
1769     /**
1770      * Saves the content of this URI to the given serial stream.
1771      *
1772      * <p> The only serializable field of a URI instance is its {@code string}
1773      * field.  That field is given a value, if it does not have one already,
1774      * and then the {@link java.io.ObjectOutputStream#defaultWriteObject()}
1775      * method of the given object-output stream is invoked. </p>
1776      *
1777      * @param  os  The object-output stream to which this object
1778      *             is to be written
1779      */

1780     private void writeObject(ObjectOutputStream os)
1781         throws IOException
1782     {
1783         defineString();
1784         os.defaultWriteObject();        // Writes the string field only
1785     }
1786 
1787     /**
1788      * Reconstitutes a URI from the given serial stream.
1789      *
1790      * <p> The {@link java.io.ObjectInputStream#defaultReadObject()} method is
1791      * invoked to read the value of the {@code string} field.  The result is
1792      * then parsed in the usual way.
1793      *
1794      * @param  is  The object-input stream from which this object
1795      *             is being read
1796      */

1797     private void readObject(ObjectInputStream is)
1798         throws ClassNotFoundException, IOException
1799     {
1800         port = -1;                      // Argh
1801         is.defaultReadObject();
1802         try {
1803             new Parser(string).parse(false);
1804         } catch (URISyntaxException x) {
1805             IOException y = new InvalidObjectException("Invalid URI");
1806             y.initCause(x);
1807             throw y;
1808         }
1809     }
1810 
1811 
1812     // -- End of public methods --
1813 
1814 
1815     // -- Utility methods for string-field comparison and hashing --
1816 




 486  * @since 1.4
 487  *
 488  * @see <a href="http://www.ietf.org/rfc/rfc2279.txt"><i>RFC&nbsp;2279: UTF-8, a
 489  * transformation format of ISO 10646</i></a>, <br><a
 490  * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC&nbsp;2373: IPv6 Addressing
 491  * Architecture</i></a>, <br><a
 492  * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC&nbsp;2396: Uniform
 493  * Resource Identifiers (URI): Generic Syntax</i></a>, <br><a
 494  * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC&nbsp;2732: Format for
 495  * Literal IPv6 Addresses in URLs</i></a>, <br><a
 496  * href="URISyntaxException.html">URISyntaxException</a>
 497  */
 498 
 499 public final class URI
 500     implements Comparable<URI>, Serializable
 501 {
 502 
 503     // Note: Comments containing the word "ASSERT" indicate places where a
 504     // throw of an InternalError should be replaced by an appropriate assertion
 505     // statement once asserts are enabled in the build.
 506     @java.io.Serial
 507     static final long serialVersionUID = -6052424284110960213L;
 508 
 509 
 510     // -- Properties and components of this instance --
 511 
 512     // Components of all URIs: [<scheme>:]<scheme-specific-part>[#<fragment>]
 513     private transient String scheme;            // null ==> relative URI
 514     private transient String fragment;
 515 
 516     // Hierarchical URI components: [//<authority>]<path>[?<query>]
 517     private transient String authority;         // Registry or server
 518 
 519     // Server-based authority: [<userInfo>@]<host>[:<port>]
 520     private transient String userInfo;
 521     private transient String host;              // null ==> registry-based
 522     private transient int port = -1;            // -1 ==> undefined
 523 
 524     // Remaining components of hierarchical URIs
 525     private transient String path;              // null ==> opaque
 526     private transient String query;


1760      *          charset
1761      */
1762     public String toASCIIString() {
1763         return encode(toString());
1764     }
1765 
1766 
1767     // -- Serialization support --
1768 
1769     /**
1770      * Saves the content of this URI to the given serial stream.
1771      *
1772      * <p> The only serializable field of a URI instance is its {@code string}
1773      * field.  That field is given a value, if it does not have one already,
1774      * and then the {@link java.io.ObjectOutputStream#defaultWriteObject()}
1775      * method of the given object-output stream is invoked. </p>
1776      *
1777      * @param  os  The object-output stream to which this object
1778      *             is to be written
1779      */
1780     @java.io.Serial
1781     private void writeObject(ObjectOutputStream os)
1782         throws IOException
1783     {
1784         defineString();
1785         os.defaultWriteObject();        // Writes the string field only
1786     }
1787 
1788     /**
1789      * Reconstitutes a URI from the given serial stream.
1790      *
1791      * <p> The {@link java.io.ObjectInputStream#defaultReadObject()} method is
1792      * invoked to read the value of the {@code string} field.  The result is
1793      * then parsed in the usual way.
1794      *
1795      * @param  is  The object-input stream from which this object
1796      *             is being read
1797      */
1798     @java.io.Serial
1799     private void readObject(ObjectInputStream is)
1800         throws ClassNotFoundException, IOException
1801     {
1802         port = -1;                      // Argh
1803         is.defaultReadObject();
1804         try {
1805             new Parser(string).parse(false);
1806         } catch (URISyntaxException x) {
1807             IOException y = new InvalidObjectException("Invalid URI");
1808             y.initCause(x);
1809             throw y;
1810         }
1811     }
1812 
1813 
1814     // -- End of public methods --
1815 
1816 
1817     // -- Utility methods for string-field comparison and hashing --
1818 


< prev index next >