@Override public List<Resource> list() { List<Resource> result = new LinkedList<>(); Path file = getFilePath(); try { if (file != null) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(file)) { for (Path child : stream) { result.add(new URLResource(child.toUri().toURL(), child.toString())); } } } } catch (IOException e) { throw new RuntimeException(e); } return result; }
@Override public String getLastModifiedString() { return DateUtils.toDateString(getLastModified()); }
@Override public String getContentType(final MimeMappings mimeMappings) { final String fileName = getName(); int index = fileName.lastIndexOf('.'); if (index != -1 && index != fileName.length() - 1) { return mimeMappings.getMimeType(fileName.substring(index + 1)); } return null; }
private URLResource getMetaInfResource(URL resourceJar, String path) { try { URL resourceUrl = new URL(resourceJar + "META-INF/resources" + path); URLResource resource = new URLResource(resourceUrl, path); if (resource.getContentLength() < 0) { return null; } return resource; } catch (MalformedURLException ex) { return null; } }
@Override public Resource getResource(final String path) throws IOException { String modPath = path; if(modPath.startsWith("/")) { modPath = path.substring(1); } final String realPath = prefix + modPath; final URL resource = classLoader.getResource(realPath); if(resource == null) { return null; } else { return new URLResource(resource, path); } }
@Override public File getFile() { Path path = getFilePath(); return path != null ? path.toFile() : null; }
@Override public Date getLastModified() { openConnection(); return lastModified; }
@Override public void serve(Sender sender, HttpServerExchange exchange, IoCallback completionCallback) { serveImpl(sender, exchange, -1, -1, false, completionCallback); }
@Override public Resource getResource(final String path) throws IOException { String modPath = path; if(modPath.startsWith("/")) { modPath = path.substring(1); } final String realPath = prefix + modPath; final URL resource = classLoader.getResource(realPath); if(resource == null) { return null; } else { return new URLResource(resource, path); } }
@Override public Resource getResource(String path) throws IOException { URL url = new URL("jar:file:" + this.jarPath + "!" + (path.startsWith("/") ? path : "/" + path)); URLResource resource = new URLResource(url, path); if (resource.getContentLength() < 0) { return null; } return resource; }
@Override public boolean isDirectory() { Path file = getFilePath(); if (file != null) { return Files.isDirectory(file); } else if (url.getPath().endsWith("/")) { return true; } return false; }
@Override public Long getContentLength() { openConnection(); return contentLength; }
@Override public void serveRange(Sender sender, HttpServerExchange exchange, long start, long end, IoCallback completionCallback) { serveImpl(sender, exchange, start, end, true, completionCallback); }
@Override public List<Resource> list() { List<Resource> result = new LinkedList<>(); Path file = getFilePath(); try { if (file != null) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(file)) { for (Path child : stream) { result.add(new URLResource(child.toUri().toURL(), child.toString())); } } } } catch (IOException e) { throw new RuntimeException(e); } return result; }
@Override public Resource getResource(final String path) throws IOException { String modPath = path; if(modPath.startsWith("/")) { modPath = path.substring(1); } final String realPath = prefix + modPath; final URL resource = classLoader.getResource(realPath); if(resource == null) { return null; } else { return new URLResource(resource, path); } }
@Override public File getFile() { Path path = getFilePath(); return path != null ? path.toFile() : null; }
@Override public Date getLastModified() { openConnection(); return lastModified; }
@Override public void serveRange(Sender sender, HttpServerExchange exchange, long start, long end, IoCallback completionCallback) { serveImpl(sender, exchange, start, end, true, completionCallback); }
@Override public String getContentType(final MimeMappings mimeMappings) { final String fileName = getName(); int index = fileName.lastIndexOf('.'); if (index != -1 && index != fileName.length() - 1) { return mimeMappings.getMimeType(fileName.substring(index + 1)); } return null; }
@Override public String getLastModifiedString() { return DateUtils.toDateString(getLastModified()); }