| | |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.ResourceBundle; |
| | | import java.util.logging.Logger; |
| | | |
| | | /** |
| | |
| | | |
| | | /* Ablageort fuer Webinhalte */ |
| | | protected final String fileBase; |
| | | |
| | | private ResourceBundle rb; |
| | | |
| | | /** |
| | | * Ein neues Objekt der Klasse FileHandler erzeugen |
| | |
| | | serveFileParts(e, new File(fileBase, fName)); |
| | | } else { |
| | | if (fName.length() < 1 || fName.endsWith(Server.SLASH)) { |
| | | fName += App.getRs(RB_WELCOME_FILE); |
| | | ResourceBundle rb = ResourceBundle.getBundle(App.RB_NAME); |
| | | fName += getResString(RB_WELCOME_FILE); |
| | | } |
| | | serveFile(e, new File(fileBase, fName)); |
| | | } |
| | |
| | | Der regulaere Ausdruck "[^\\d-,]" bezeichnet alle Zeichen, die keine |
| | | Ziffern 0-9, Bindestrich oder Komma sind. |
| | | */ |
| | | rangeHeader = rangeHeader.replaceAll(App.getRs(RB_RANGE_PATTERN), ""); |
| | | rangeHeader = rangeHeader.replaceAll(getResString(RB_RANGE_PATTERN), ""); |
| | | |
| | | /* |
| | | Die Ranges ermitteln. |
| | |
| | | String[] rangeArray = rangeHeader.split(STR_COMMA); |
| | | for (String rangeStr : rangeArray) { |
| | | Range range = new Range(); |
| | | String[] values = rangeStr.split(App.getRs(RB_DASH)); |
| | | String[] values = rangeStr.split(getResString(RB_DASH)); |
| | | if (values.length < 2) { |
| | | // Fall 3 |
| | | range.setStart(Long.parseLong(values[0])); |
| | | range.setEnd(file.length()); |
| | | //range.setEnd(file.length()); |
| | | range.setEnd(Long.MAX_VALUE); |
| | | } else { |
| | | if (values[0].length() < 1) { |
| | | // Fall 1 |
| | |
| | | */ |
| | | protected String contentRangeHdr(Range range, File file) { |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append(App.getRs(RB_BYTES)); |
| | | sb.append(getResString(RB_BYTES)); |
| | | sb.append(STR_BLANK); |
| | | sb.append(range.getStart()); |
| | | sb.append(App.getRs(RB_DASH)); |
| | | sb.append(getResString(RB_DASH)); |
| | | sb.append(range.getEnd()); |
| | | sb.append(Server.SLASH); |
| | | sb.append(file.length()); |
| | |
| | | */ |
| | | protected void setHeaders(HttpExchange e, File file) throws IOException { |
| | | Headers resHeaders = e.getResponseHeaders(); |
| | | resHeaders.add(ACCEPT_RANGES_HEADER, App.getRs(RB_BYTES)); |
| | | resHeaders.add(ACCEPT_RANGES_HEADER, getResString(RB_BYTES)); |
| | | String mimeType = Files.probeContentType(file.toPath()); |
| | | if (mimeType != null) { |
| | | resHeaders.add(CONTENT_TYPE, mimeType); |
| | | } |
| | | SimpleDateFormat sdf = new SimpleDateFormat(App.getRs(RB_LM_PATTERN)); |
| | | SimpleDateFormat sdf = new SimpleDateFormat(getResString(RB_LM_PATTERN)); |
| | | Date date = new Date(file.lastModified()); |
| | | resHeaders.add(LAST_MODIFIED_DATE_HEADER, sdf.format(date)); |
| | | } |
| | |
| | | */ |
| | | protected void sendNotFound(HttpExchange e, String fname) throws IOException { |
| | | OutputStream os = e.getResponseBody(); |
| | | String response = fname + STR_BLANK + App.getRs(RB_NOT_FOUND); |
| | | String response = fname + STR_BLANK + getResString(RB_NOT_FOUND); |
| | | byte[] bytes = response.getBytes(StandardCharsets.UTF_8); |
| | | e.sendResponseHeaders(SC_NOT_FOUND, bytes.length); |
| | | os.write(bytes); |
| | |
| | | return ranges.iterator(); |
| | | } |
| | | } |
| | | |
| | | protected String getResString(String key) { |
| | | if(rb == null) { |
| | | rb = ResourceBundle.getBundle(App.RB_NAME); |
| | | } |
| | | return rb.getString(key); |
| | | } |
| | | } |