Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>17.1.1</version>
<version>23.0.0</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -98,7 +98,6 @@
<license.copyrightOwners>KNIME GmbH and Board of Regents of the University
of Wisconsin-Madison.</license.copyrightOwners>

<scijava-common.version>2.65.0</scijava-common.version>
<okhttp.version>3.6.0</okhttp.version>

<!-- NB: Deploy releases to the ImageJ Maven repository. -->
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/scijava/io/http/HTTPLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.Objects;

import org.scijava.io.location.AbstractRemoteLocation;
Expand Down Expand Up @@ -136,4 +137,13 @@ public HttpUrl getHttpUrl() {
public URI getURI() {
return url.uri();
}

/**
* @return the last path element
*/
@Override
public String getName() {
final List<String> segs = url.pathSegments();
return segs.get(segs.size() - 1);
}
}
23 changes: 23 additions & 0 deletions src/main/java/org/scijava/io/http/HTTPLocationResolver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

package org.scijava.io.http;

import java.net.URI;
import java.net.URISyntaxException;

import org.scijava.io.location.AbstractLocationResolver;
import org.scijava.io.location.Location;
import org.scijava.io.location.LocationResolver;
import org.scijava.plugin.Plugin;

@Plugin(type = LocationResolver.class)
public class HTTPLocationResolver extends AbstractLocationResolver {

public HTTPLocationResolver() {
super("http", "https");
}

@Override
public Location resolve(URI uri) throws URISyntaxException {
return new HTTPLocation(uri);
}
}
37 changes: 37 additions & 0 deletions src/test/java/org/scijava/io/http/HTTPLocationResolverTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

package org.scijava.io.http;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.net.URISyntaxException;

import org.junit.Test;
import org.scijava.Context;
import org.scijava.io.handle.DataHandleService;
import org.scijava.io.location.Location;
import org.scijava.io.location.LocationService;

public class HTTPLocationResolverTest {

final Context context = new Context();
final DataHandleService dataHandleService = context.service(
DataHandleService.class);
final LocationService resolver = context.service(LocationService.class);

/**
* Tests the location creation with a file located on Github
*
* @throws URISyntaxException
*/
@Test
public void testDataHandleRemote() throws IOException, URISyntaxException {

String url =
"https://github.com/scijava/scijava-io-http/blob/master/src/test/resources/testfile?raw=true";
final Location loc = new HTTPLocation(url);
final Location locResolved = resolver.resolve(url);

assertEquals(loc, locResolved);
}
}