| 14 | import java.io.InputStream; |
| 15 | |
| 16 | public final class URL { |
| 17 | private final URLStreamHandler handler; |
| 18 | private String protocol; |
| 19 | private String host; |
| 20 | private int port; |
| 21 | private String file; |
| 22 | private String path; |
| 23 | private String query; |
| 24 | private String ref; |
| 25 | |
| 26 | public URL(String s) throws MalformedURLException { |
| 27 | int colon = s.indexOf(':'); |
| 28 | int slash = s.indexOf('/'); |
| 29 | if (colon > 0 && (slash < 0 || colon < slash)) { |
| 30 | handler = findHandler(s.substring(0, colon)); |
| 31 | handler.parseURL(this, s, colon + 1, s.length()); |
| 32 | } else { |
| 33 | throw new MalformedURLException(s); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | public String toString() { |
| 38 | return handler.toExternalForm(this); |
| 39 | } |
| 40 | |
| 41 | public String getProtocol() { |
| 42 | return protocol; |
| 43 | } |
| 44 | |
| 45 | public String getHost() { |
| 46 | return host; |
| 47 | } |
| 48 | |
| 49 | public int getPort() { |
| 50 | return port; |
| 51 | } |
| 52 | |
| 53 | public String getFile() { |
| 54 | return file; |
| 55 | } |
| 56 | |
| 57 | public String getRef() { |
| 58 | return ref; |
| 59 | } |
| 60 | |
| 61 | public String getPath() { |
| 62 | return path; |
| 63 | } |
| 64 | |
| 65 | public String getQuery() { |
| 66 | return query; |
| 67 | } |
| 68 | |
| 69 | public URLConnection openConnection() throws IOException { |
| 70 | return handler.openConnection(this); |
| 71 | } |
| 72 | |
| 73 | public InputStream openStream() throws IOException { |
nothing calls this directly
no outgoing calls
no test coverage detected