1
1
package j2html .tags ;
2
2
3
+ import java .io .BufferedReader ;
4
+ import java .io .FileReader ;
3
5
import java .io .IOException ;
4
- import java .nio .file .Files ;
5
- import java .nio .file .Path ;
6
- import java .nio .file .Paths ;
7
6
8
7
import j2html .utils .CSSMin ;
9
8
import j2html .utils .JSMin ;
10
9
11
- import static j2html .TagCreator .rawHtml ;
12
- import static j2html .TagCreator .script ;
13
- import static j2html .TagCreator .style ;
10
+ import static j2html .TagCreator .*;
14
11
15
12
public class InlineStaticResource {
16
13
@@ -29,18 +26,27 @@ public static ContainerTag get(String path, TargetFormat format) {
29
26
30
27
public static String getFileAsString (String path ) {
31
28
try {
32
- return readFileAsString (Paths . get ( InlineStaticResource .class .getResource (path ).toURI () ));
29
+ return readFileAsString (InlineStaticResource .class .getResource (path ).getPath ( ));
33
30
} catch (Exception e1 ) {
34
31
try {
35
- return readFileAsString (Paths . get ( path ) );
32
+ return readFileAsString (path );
36
33
} catch (Exception e2 ) {
37
34
throw new RuntimeException ("Couldn't find file with path='" + path + "'" );
38
35
}
39
36
}
40
37
}
41
38
42
- private static String readFileAsString (Path path ) throws IOException {
43
- return new String (Files .readAllBytes (path ), "UTF-8" );
39
+ /**
40
+ * @author kjheimark <3
41
+ */
42
+ private static String readFileAsString (String path ) throws IOException {
43
+ BufferedReader bufferedReader = new BufferedReader (new FileReader (path ));
44
+ StringBuilder sb = new StringBuilder ();
45
+ int c ;
46
+ while ((c = bufferedReader .read ()) >= 0 && c >= 0 ) {
47
+ sb .append ((char ) c );
48
+ }
49
+ return sb .toString ();
44
50
}
45
51
46
52
}
0 commit comments