From ad3e2db5eefd3093a066e7b61df0653abc9b6f2e Mon Sep 17 00:00:00 2001 From: ulrich Date: Fri, 07 May 2021 14:05:08 +0000 Subject: [PATCH] Nicht erforderliche globale Variablen entfernt --- src/de/uhilger/tango/api/FileHandler.java | 27 +++++++++++++++++++-------- 1 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/de/uhilger/tango/api/FileHandler.java b/src/de/uhilger/tango/api/FileHandler.java index 05b8bbd..40edfed 100644 --- a/src/de/uhilger/tango/api/FileHandler.java +++ b/src/de/uhilger/tango/api/FileHandler.java @@ -34,6 +34,7 @@ import java.util.Date; import java.util.Iterator; import java.util.List; +import java.util.ResourceBundle; import java.util.logging.Logger; /** @@ -83,6 +84,8 @@ /* Ablageort fuer Webinhalte */ protected final String fileBase; + + private ResourceBundle rb; /** * Ein neues Objekt der Klasse FileHandler erzeugen @@ -115,7 +118,8 @@ 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)); } @@ -257,7 +261,7 @@ 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. @@ -280,7 +284,7 @@ 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])); @@ -311,10 +315,10 @@ */ 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()); @@ -333,12 +337,12 @@ */ 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)); } @@ -353,7 +357,7 @@ */ 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); @@ -452,4 +456,11 @@ return ranges.iterator(); } } + + protected String getResString(String key) { + if(rb == null) { + rb = ResourceBundle.getBundle(App.RB_NAME); + } + return rb.getString(key); + } } -- Gitblit v1.9.3