• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.url;
6 
7 import java.net.URISyntaxException;
8 
9 /**
10  * An API shim around GURL that mostly matches the java.net.URI API.
11  *
12  * @deprecated Please use GURL directly in new code.
13  */
14 @Deprecated
15 public class URI extends GURL {
16     /** Create a new GURL with a java.net.URI API shim. */
URI(String uri)17     public URI(String uri) throws URISyntaxException {
18         super(uri);
19         if (!isValid()) {
20             throw new URISyntaxException(uri, "Uri could not be parsed as a valid GURL");
21         }
22     }
23 
URI()24     private URI() {}
25 
26     /**
27      * This function is a convenience wrapper around {@link URI#URI(String)}, that wraps the thrown
28      * thrown URISyntaxException in an IllegalArgumentException and throws that instead.
29      */
create(String str)30     public static URI create(String str) {
31         try {
32             return new URI(str);
33         } catch (URISyntaxException e) {
34             throw new IllegalArgumentException(e);
35         }
36     }
37 
38     @Override
getOrigin()39     public URI getOrigin() {
40         URI target = new URI();
41         getOriginInternal(target);
42         return target;
43     }
44 
45     /** See {@link GURL#getRef()} */
getFragment()46     public String getFragment() {
47         return getRef();
48     }
49 
50     /** See {@link java.net.URI#isAbsolute()} */
isAbsolute()51     public boolean isAbsolute() {
52         return !getScheme().isEmpty();
53     }
54 
55     @Override
toString()56     public String toString() {
57         return getPossiblyInvalidSpec();
58     }
59 }
60