Skip to content

Commit 145aa42

Browse files
committed
Implement LocationResolver
1 parent 044bd24 commit 145aa42

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
package org.scijava.io.http;
3+
4+
import java.net.URI;
5+
import java.net.URISyntaxException;
6+
7+
import org.scijava.io.location.Location;
8+
import org.scijava.io.location.resolve.AbstractLocationResolver;
9+
import org.scijava.io.location.resolve.LocationResolver;
10+
import org.scijava.plugin.Plugin;
11+
12+
@Plugin(type = LocationResolver.class)
13+
public class HTTPLocationResolver extends AbstractLocationResolver {
14+
15+
public HTTPLocationResolver() {
16+
super("http", "htpps");
17+
}
18+
19+
@Override
20+
public Location resolve(URI uri) throws URISyntaxException {
21+
return new HTTPLocation(uri);
22+
}
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
package org.scijava.io.http;
3+
4+
import static org.junit.Assert.assertEquals;
5+
6+
import java.io.IOException;
7+
import java.net.URISyntaxException;
8+
9+
import org.scijava.Context;
10+
import org.scijava.io.handle.DataHandleService;
11+
import org.scijava.io.location.Location;
12+
import org.scijava.io.location.resolve.LocationResolverService;
13+
14+
public class HTTPLocationResolverTest {
15+
16+
final Context context = new Context(DataHandleService.class);
17+
final DataHandleService dataHandleService = context.service(
18+
DataHandleService.class);
19+
final LocationResolverService resolver = context.service(
20+
LocationResolverService.class);
21+
22+
/**
23+
* Tests the location creation with a file located on Github
24+
*
25+
* @throws URISyntaxException
26+
*/
27+
public void testDataHandleRemote() throws IOException, URISyntaxException {
28+
29+
String url =
30+
"https://github.com/scijava/scijava-io-http/blob/master/src/test/resources/testfile?raw=true";
31+
final Location loc = new HTTPLocation(url);
32+
final Location locResolved = resolver.resolve(url);
33+
34+
assertEquals(loc, locResolved);
35+
}
36+
}

0 commit comments

Comments
 (0)