| | |
| | | import com.sun.net.httpserver.HttpHandler; |
| | | import de.uhilger.mediaz.App; |
| | | import de.uhilger.mediaz.Server; |
| | | import static de.uhilger.mediaz.Server.RB_SLASH; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | |
| | | * @author Ulrich Hilger |
| | | * @version 0.1, 25. März 2021 |
| | | */ |
| | | public class FileHandler implements HttpHandler { |
| | | public class FileHandler extends JsonHelper implements HttpHandler { |
| | | |
| | | /* Der Logger fuer diesen FileHandler */ |
| | | private static final Logger logger = Logger.getLogger(FileHandler.class.getName()); |
| | |
| | | public static final String RB_WELCOME_FILE = "welcomeFile"; |
| | | |
| | | /* Ablageort fuer Webinhalte */ |
| | | private final String fileBase; |
| | | protected final String fileBase; |
| | | |
| | | /** |
| | | * Ein neues Objekt der Klasse FileHandler erzeugen |
| | |
| | | if (headers.containsKey(RANGE_HEADER)) { |
| | | serveFileParts(e, new File(fileBase, fName)); |
| | | } else { |
| | | if (fName.length() < 1 || fName.endsWith(App.getRs(RB_SLASH))) { |
| | | if (fName.length() < 1 || fName.endsWith(Server.SLASH)) { |
| | | fName += App.getRs(RB_WELCOME_FILE); |
| | | } |
| | | serveFile(e, new File(fileBase, fName)); |
| | |
| | | protected String getFileName(HttpExchange e) { |
| | | String ctxPath = e.getHttpContext().getPath(); |
| | | String uriPath = e.getRequestURI().getPath(); |
| | | logger.info(uriPath); |
| | | logger.fine(uriPath); |
| | | return uriPath.substring(ctxPath.length()); |
| | | } |
| | | |
| | |
| | | sb.append(range.getStart()); |
| | | sb.append(App.getRs(RB_DASH)); |
| | | sb.append(range.getEnd()); |
| | | sb.append(App.getRs(RB_SLASH)); |
| | | sb.append(Server.SLASH); |
| | | sb.append(file.length()); |
| | | return sb.toString(); |
| | | } |