Skip to content

Instantly share code, notes, and snippets.

@brunoborges
Created January 15, 2013 21:09
Show Gist options
  • Save brunoborges/4542085 to your computer and use it in GitHub Desktop.
Save brunoborges/4542085 to your computer and use it in GitHub Desktop.
JEP for adding getBaseURL() into java.net.URL

Title: Method for returning the base URL of a java.net.URL object Author: Bruno Borges Organization: Oracle Owner: Bruno Borges Created: 2013/01/15 Type: Feature State: Draft Exposure: Open Component: core/net Scope: SE JSR: 337 Discussion: net dash dev at openjdk dot java dot net Start: 2013/Q1 Effort: XS Duration: XS Template: 1.0

Summary

Method for returning the base URL of a given URL object, as of 'protocol://host:port'.

Motivation

Boiler-plate code is needed to extract the base URL of a given URL object. This method will standardize and provide a basic feature.

Description

The java.net.URL class should provide a getBaseURL method that returns another URL object, based on the protocol://hostname:port of the original URL object. Nothing else should be added to the base URL object, for example path or query string.

Testing

Given the following URL: http://openjdk.java.net/jeps/1, the getBaseURL method must return a URL object representing "http://openjdk.java.net"

Impact

  • User experience: no need to create boiler-plate code, or use 3rd-party libraries.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment