Commit 4db76b07 authored by leMaik's avatar leMaik
Browse files

Fix wrong urls. Fix connections to remote files not being closed.

parent 89aec2b6
......@@ -25,7 +25,7 @@ public class HttpRemoteDynmapServer extends AbstractDynmapServer {
if (path.startsWith("/")) {
return new HttpRemoteFile(url + path.substring(1));
} else {
return new HttpRemoteFile(url + path.substring(1));
return new HttpRemoteFile(url + path);
}
} else {
if (path.startsWith("/")) {
......
......@@ -9,6 +9,7 @@ public class HttpRemoteFile implements AbstractFile {
private final String url;
private final boolean exists;
private final long length;
private final long lastModified;
private final HttpURLConnection connection;
public HttpRemoteFile(String url) throws IOException {
......@@ -20,11 +21,62 @@ public class HttpRemoteFile implements AbstractFile {
int responseCode = connection.getResponseCode();
exists = responseCode != 404;
length = connection.getContentLengthLong();
lastModified = connection.getLastModified();
}
@Override
public InputStream getInputStream() throws IOException {
return connection.getInputStream();
return new InputStream() {
private InputStream inputStream = connection.getInputStream();
public int read() throws IOException {
return inputStream.read();
}
@Override
public int read(byte[] b) throws IOException {
return inputStream.read(b);
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
return inputStream.read(b, off, len);
}
@Override
public long skip(long n) throws IOException {
return inputStream.skip(n);
}
@Override
public int available() throws IOException {
return inputStream.available();
}
@Override
public void close() throws IOException {
try {
inputStream.close();
} finally {
connection.disconnect();
}
}
@Override
public synchronized void mark(int readlimit) {
inputStream.mark(readlimit);
}
@Override
public synchronized void reset() throws IOException {
inputStream.reset();
}
@Override
public boolean markSupported() {
return inputStream.markSupported();
}
};
}
@Override
......@@ -34,7 +86,7 @@ public class HttpRemoteFile implements AbstractFile {
@Override
public long lastModified() {
return 0;
return lastModified;
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment