package j2html.tags;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import j2html.utils.CSSMin;
import j2html.utils.JSMin;

import static j2html.TagCreator.rawHtml;
import static j2html.TagCreator.script;
import static j2html.TagCreator.style;

public class InlineStaticResource {

    public enum TargetFormat {CSS_MIN, CSS, JS_MIN, JS}

    public static ContainerTag get(String path, TargetFormat format) {
        String fileString = getFileAsString(path);
        switch (format) {
            case CSS_MIN : return style().with(rawHtml(CSSMin.compress(fileString)));
            case JS_MIN  : return script().with(rawHtml(JSMin.compressJs(fileString)));
            case CSS     : return style().with(rawHtml(fileString));
            case JS      : return script().with(rawHtml(fileString));
            default      : throw new RuntimeException("Invalid target format");
        }
    }

    public static String getFileAsString(String path) {
        try {
            return readFileAsString(Paths.get(InlineStaticResource.class.getResource(path).toURI()));
        } catch (Exception e1) {
            try {
                return readFileAsString(Paths.get(path));
            } catch (Exception e2) {
                throw new RuntimeException("Couldn't find file with path='" + path + "'");
            }
        }
    }

    private static String readFileAsString(Path path) throws IOException {
        return new String(Files.readAllBytes(path), "UTF-8");
    }

}


@@ -30,27 +30,30 @@
 java.io.
-IOException
+BufferedReader
 ;%0Aimport
@@ -62,22 +62,21 @@
 ava.
-n
 io.
-file.Files
+FileReader
 ;%0Aim
@@ -89,49 +89,22 @@
 ava.
-n
 io.
-file.Path;%0Aimport java.nio.file.Paths
+IOException
 ;%0A%0Ai
@@ -194,94 +194,9 @@
 tor.
-rawHtml;%0Aimport static j2html.TagCreator.script;%0Aimport static j2html.TagCreator.style
+*
 ;%0A%0Ap
@@ -952,26 +952,16 @@
 sString(
-Paths.get(
 InlineSt
@@ -1001,15 +1001,16 @@
 th).
-toURI()
+getPath(
 ));%0A
@@ -1104,24 +1104,13 @@
 ing(
-Paths.get(
 path)
-)
 ;%0A  
@@ -1262,24 +1262,68 @@
    %7D%0A    %7D%0A%0A
+    /**%0A     * @author kjheimark %3C3%0A     */%0A
     private 
@@ -1353,20 +1353,22 @@
 sString(
-Path
+String
  path) t
@@ -1399,59 +1399,276 @@
     
-return new String(Files.readAllBytes(path), %22UTF-8%22
+BufferedReader bufferedReader = new BufferedReader(new FileReader(path));%0A        StringBuilder sb = new StringBuilder();%0A        int c;%0A        while ((c = bufferedReader.read()) %3E= 0 && c %3E= 0) %7B%0A            sb.append((char) c);%0A        %7D%0A        return sb.toString(
 );%0A 

Make filereader java6 compatible, because why not