From 03b95f100b605458e5bf2995e955882d9aa51868 Mon Sep 17 00:00:00 2001
From: undisclosed
Date: Mon, 23 Jan 2023 13:28:17 +0000
Subject: [PATCH] URL in m3u berichtigt

---
 src/de/uhilger/tango/api/FileHandler.java |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/de/uhilger/tango/api/FileHandler.java b/src/de/uhilger/tango/api/FileHandler.java
index 05b8bbd..d0299e1 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,11 +284,12 @@
     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
@@ -311,10 +316,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 +338,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 +358,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 +457,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