Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public URI getUri() {

@Override
public FSDataInputStream open(Path path, int bufferSize) throws IOException {
URLConnection conn = path.toUri().toURL().openConnection();
URI pathUri = makeQualified(path).toUri();
URLConnection conn = pathUri.toURL().openConnection();
InputStream in = conn.getInputStream();
return new FSDataInputStream(new HttpDataInputStream(in));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.stream.IntStream;

import static org.junit.Assert.assertEquals;

Expand All @@ -48,20 +49,26 @@ public void testHttpFileSystem() throws IOException, URISyntaxException,
final String data = "foo";

try (MockWebServer server = new MockWebServer()) {
server.enqueue(new MockResponse().setBody(data));
IntStream.rangeClosed(1, 3).forEach(i -> server.enqueue(new MockResponse().setBody(data)));
server.start();
URI uri = URI.create(String.format("http://%s:%d", server.getHostName(),
server.getPort()));
FileSystem fs = FileSystem.get(uri, conf);
try (InputStream is = fs.open(
new Path(new URL(uri.toURL(), "/foo").toURI()),
4096)) {
byte[] buf = new byte[data.length()];
IOUtils.readFully(is, buf, 0, buf.length);
assertEquals(data, new String(buf, StandardCharsets.UTF_8));
}
assertSameData(fs, new Path(new URL(uri.toURL(), "/foo").toURI()), data);
assertSameData(fs, new Path("/foo"), data);
assertSameData(fs, new Path("foo"), data);
RecordedRequest req = server.takeRequest();
assertEquals("/foo", req.getPath());
}
}

private void assertSameData(FileSystem fs, Path path, String data) throws IOException {
try (InputStream is = fs.open(
path,
4096)) {
byte[] buf = new byte[data.length()];
IOUtils.readFully(is, buf, 0, buf.length);
assertEquals(data, new String(buf, StandardCharsets.UTF_8));
}
}
}