url-scheme-registry

Convenience library for registering java.net.URL handlers

License

License

GroupId

GroupId

org.skife.url
ArtifactId

ArtifactId

url-scheme-registry
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

url-scheme-registry
Convenience library for registering java.net.URL handlers
Project URL

Project URL

http://github.com/brianm/url-scheme-registry
Source Code Management

Source Code Management

http://github.com/brianm/url-scheme-registry/tree/master

Download url-scheme-registry

How to add to project

<!-- https://jarcasting.com/artifacts/org.skife.url/url-scheme-registry/ -->
<dependency>
    <groupId>org.skife.url</groupId>
    <artifactId>url-scheme-registry</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.skife.url/url-scheme-registry/
implementation 'org.skife.url:url-scheme-registry:0.0.1'
// https://jarcasting.com/artifacts/org.skife.url/url-scheme-registry/
implementation ("org.skife.url:url-scheme-registry:0.0.1")
'org.skife.url:url-scheme-registry:jar:0.0.1'
<dependency org="org.skife.url" name="url-scheme-registry" rev="0.0.1">
  <artifact name="url-scheme-registry" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.skife.url', module='url-scheme-registry', version='0.0.1')
)
libraryDependencies += "org.skife.url" % "url-scheme-registry" % "0.0.1"
[org.skife.url/url-scheme-registry "0.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
cglib : cglib-nodep jar 2.2.2

test (3)

Group / Artifact Type Version
com.google.guava : guava jar 12.0
junit : junit-dep jar 4.10
org.easytesting : fest-assert jar 1.4

Project Modules

There are no modules declared in this project.

Library to make it easy to register new URL schemes for java.net.URL. Consider:

@Test
public void testRegisterHandler() throws Exception
{
    UrlSchemeRegistry.register("dinner", DinnerHandler.class);

    assertThat(read(new URL("dinner://steak"))).isEqualTo("steak");
}

which uses the URL handler:

public class DinnerHandler extends URLStreamHandler
{
  @Override
  protected URLConnection openConnection(URL u) throws IOException
  {
    final String breakfast = u.getHost();
    return new URLConnection(u)
    {
      @Override
      public void connect() throws IOException { }

      @Override
      public InputStream getInputStream() throws IOException
      {
          return new ByteArrayInputStream(breakfast.getBytes());
      }
    };
  }
}

The library uses the java.protocol.handler.pkgs system property and runtime generated classes following the correct package and class name conventions to accomplish this. It does not use URL.setURLStreamHandlerFactory(...); for this (so code using this library should run fine inside Tomcat which does use that method).

Releases are distributed via Maven Central. There are two variants, one with a dependency on cglib-2.2.2

<dependency>
    <groupId>org.skife.url</groupId>
    <artifactId>url-scheme-registry</artifactId>
    <version>0.0.1</version>
</dependency>

or and one which renamespaces and bundles cglib-2.2.2.

<dependency>
    <groupId>org.skife.url</groupId>
    <artifactId>url-scheme-registry</artifactId>
    <classifier>nodep</classifier>
    <version>0.0.1</version>
</dependency>

Good luck!

Versions

Version
0.0.1