package com.manolosmobile.site;

import static spark.Spark.get;
import static spark.Spark.port;
import static spark.Spark.staticFileLocation;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

public class ManolosMobile {

	public static void main(String[] args) {
		setPortFromEnvVariable();
		staticFileLocation("/static");
		
		String message = "";
		URL url = ManolosMobile.class.getResource("/static/index.html");
		if (url == null) {
			message += "url is null ";
		} else {
			message += "url:" + url.toString();
		}
		
		final String finalMessage = message;
		get("/", (req, res) -> finalMessage);
	}

	private static void setPortFromEnvVariable() {
        String port = System.getenv("PORT");
        if (port != null && !port.trim().isEmpty()) {
            port(Integer.parseInt(port));
        } else {
            port(8080);
        }
    }
	
	private static String renderHtmlContent(String htmlFile) {
		try {
			return new String(Files.readAllBytes(Paths.get(ManolosMobile.class.getResource(htmlFile).toURI())), StandardCharsets.UTF_8);
		} catch (IOException | URISyntaxException e) {
			e.printStackTrace();
			return "Error :(";
		}
	}
	
}

@@ -180,524 +180,278 @@
 ava.
-net.URISyntaxException;%0Aimport java.net.URL;%0Aimport java.nio.charset.StandardCharsets;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Paths;%0A%0Apublic class ManolosMobile %7B%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09setPortFromEnvVariable();%0A%09%09staticFileLocation(%22/static%22);%0A%09%09%0A%09%09String message = %22%22;%0A%09%09URL url = ManolosMobile.class.getResource(%22/static/index.html%22);%0A%09%09if (url == null) %7B%0A%09%09%09message += %22url is null %22;%0A%09%09%7D else %7B%0A%09%09%09message += %22url:%22 + url.toString();%0A%09%09%7D%0A%09%09%0A%09%09final String finalMessage = message;
+io.InputStream;%0A%0Aimport spark.utils.IOUtils;%0A%0Apublic class ManolosMobile %7B%0A%0A%09private static String indexHtmlContent;%0A%09%0A%09public static void main(String%5B%5D args) %7B%0A%09%09setPortFromEnvVariable();%0A%09%09staticFileLocation(%22/static%22);%0A%09%09initIndexHtmlContent(%22/static/index.html%22);%0A%09%09
 %0A%09%09g
@@ -476,20 +476,24 @@
  -%3E 
-f
 in
-alMessage
+dexHtmlContent
 );%0A%09
@@ -720,17 +720,17 @@
  port(80
-8
+9
 0);%0A    
@@ -763,21 +763,22 @@
 tic 
-String render
+void initIndex
 Html
@@ -808,66 +808,46 @@
 ) %7B%0A
-%09%09try %7B%0A%09%09%09return new String(Files.readAllBytes(Paths.get(
+        try (InputStream htmlStream = 
 Mano
@@ -873,16 +873,24 @@
 Resource
+AsStream
 (htmlFil
@@ -895,79 +895,77 @@
 ile)
-.toURI())), StandardCharsets.UTF_8);%0A%09%09%7D catch (IOException %7C URISyntax
+) %7B%0A%09%09%09indexHtmlContent = IOUtils.toString(htmlStream);%0A%09%09%7D catch (IO
 Exce
@@ -1006,14 +1006,26 @@
 %0A%09%09%09
-return
+indexHtmlContent =
  %22Er

Test final