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 /** 17 * Create a new GURL with a java.net.URI API shim. 18 */ URI(String uri)19 public URI(String uri) throws URISyntaxException { 20 super(uri); 21 if (!isValid()) { 22 throw new URISyntaxException(uri, "Uri could not be parsed as a valid GURL"); 23 } 24 } 25 URI()26 private URI() {} 27 28 /** 29 * This function is a convenience wrapper around {@link URI#URI(String)}, that wraps the thrown 30 * thrown URISyntaxException in an IllegalArgumentException and throws that instead. 31 */ create(String str)32 public static URI create(String str) { 33 try { 34 return new URI(str); 35 } catch (URISyntaxException e) { 36 throw new IllegalArgumentException(e); 37 } 38 } 39 40 @Override getOrigin()41 public URI getOrigin() { 42 URI target = new URI(); 43 getOriginInternal(target); 44 return target; 45 } 46 47 /** See {@link GURL#getRef()} */ getFragment()48 public String getFragment() { 49 return getRef(); 50 } 51 52 /** See {@link java.net.URI#isAbsolute()} */ isAbsolute()53 public boolean isAbsolute() { 54 return !getScheme().isEmpty(); 55 } 56 57 @Override toString()58 public String toString() { 59 return getPossiblyInvalidSpec(); 60 } 61 } 62