diff --git a/gradle.properties b/gradle.properties index e44f668..c7fa873 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group = org.xbib name = net-http -version = 4.4.2 +version = 4.4.3 diff --git a/net-http-server/src/main/java/org/xbib/net/http/server/resource/AbstractResourceHandler.java b/net-http-server/src/main/java/org/xbib/net/http/server/resource/AbstractResourceHandler.java index c62a161..dba070c 100644 --- a/net-http-server/src/main/java/org/xbib/net/http/server/resource/AbstractResourceHandler.java +++ b/net-http-server/src/main/java/org/xbib/net/http/server/resource/AbstractResourceHandler.java @@ -234,12 +234,12 @@ public abstract class AbstractResourceHandler implements HttpHandler { } } } - if (ranges.isEmpty() || ranges.get(0) == full) { + if (ranges.isEmpty() || ranges.getFirst() == full) { context.header(HttpHeaderNames.CONTENT_RANGE, "bytes " + full.start + '-' + full.end + '/' + full.total) .header(HttpHeaderNames.CONTENT_LENGTH, Long.toString(full.length)); send(resource, HttpResponseStatus.OK, contentType, context, full.start, full.length); } else if (ranges.size() == 1) { - Range r = ranges.get(0); + Range r = ranges.getFirst(); context.header(HttpHeaderNames.CONTENT_RANGE, "bytes " + r.start + '-' + r.end + '/' + r.total) .header(HttpHeaderNames.CONTENT_LENGTH, Long.toString(r.length)); send(resource, HttpResponseStatus.PARTIAL_CONTENT, contentType, context, r.start, r.length); @@ -275,7 +275,7 @@ public abstract class AbstractResourceHandler implements HttpHandler { private static long sublong(String value, int beginIndex, int endIndex) { String substring = value.substring(beginIndex, endIndex); - return substring.length() > 0 ? Long.parseLong(substring) : -1; + return !substring.isEmpty() ? Long.parseLong(substring) : -1; } protected void send(Resource resource, @@ -300,6 +300,9 @@ public abstract class AbstractResourceHandler implements HttpHandler { } else { if ("file".equals(url.getScheme())) { Path path = resource.getPath(); + if (path == null) { + path = Paths.get(url.toURI()); + } try (FileChannel fileChannel = (FileChannel) Files.newByteChannel(path)) { send(fileChannel, httpResponseStatus, contentType, context, offset, size); } catch (IOException e) {