Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

brianm/url-scheme-registry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

Java java.net.URL Scheme Registry Helper

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages