| | |
| | | public static final String ACCEPT_RANGES_HEADER = "Accept-Ranges"; |
| | | public static final String LAST_MODIFIED_DATE_HEADER = "Last-Modified"; |
| | | public static final String CONTENT_TYPE = "Content-Type"; |
| | | public static final String CONTENT_LENGTH = "Content-Length"; |
| | | |
| | | /* Statuscodes */ |
| | | public static final int SC_OK = 200; |
| | |
| | | if (headers.containsKey(RANGE_HEADER)) { |
| | | serveFileParts(e, new File(fileBase, fName)); |
| | | } else { |
| | | if (fName.endsWith(Server.STR_SLASH)) { |
| | | if (fName.length() < 1 || fName.endsWith(Server.STR_SLASH)) { |
| | | fName += WELCOME_FILE; |
| | | } |
| | | serveFile(e, new File(fileBase, fName)); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Den Namen der gewünschten Datei aus der HTTP-Anfrage ermitteln |
| | | * |
| | | * @param e das Objekt mit Methoden zur Untersuchung der Anfrage sowie zum |
| | | * Anfertigen und Senden der Antwort |
| | | * @return Name der gewünschten Datei |
| | | */ |
| | | protected String getFileName(HttpExchange e) { |
| | | String ctxPath = e.getHttpContext().getPath(); |
| | | String uriPath = e.getRequestURI().getPath(); |
| | |
| | | protected void serveFile(HttpExchange e, File file) throws IOException { |
| | | if (file.exists()) { |
| | | setHeaders(e, file); |
| | | e.getResponseHeaders().set(CONTENT_LENGTH, Long.toString(file.length())); |
| | | e.sendResponseHeaders(SC_OK, file.length()); |
| | | if(HTTP_GET.equalsIgnoreCase(e.getRequestMethod())) { |
| | | InputStream in = new FileInputStream(file); |
| | |
| | | * aus Bytes, der sich aus den Bytepositionen des Beginns und Endes |
| | | * des Bereiches ergibt. |
| | | */ |
| | | class Range { |
| | | public class Range { |
| | | |
| | | private long start; |
| | | private long end; |