Skip to content

Commit 97a8f34

Browse files
committed
Make filereader java6 compatible, because why not
1 parent 6305e36 commit 97a8f34

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/main/java/j2html/tags/InlineStaticResource.java

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package j2html.tags;
22

3+
import java.io.BufferedReader;
4+
import java.io.FileReader;
35
import java.io.IOException;
4-
import java.nio.file.Files;
5-
import java.nio.file.Path;
6-
import java.nio.file.Paths;
76

87
import j2html.utils.CSSMin;
98
import j2html.utils.JSMin;
109

11-
import static j2html.TagCreator.rawHtml;
12-
import static j2html.TagCreator.script;
13-
import static j2html.TagCreator.style;
10+
import static j2html.TagCreator.*;
1411

1512
public class InlineStaticResource {
1613

@@ -29,18 +26,27 @@ public static ContainerTag get(String path, TargetFormat format) {
2926

3027
public static String getFileAsString(String path) {
3128
try {
32-
return readFileAsString(Paths.get(InlineStaticResource.class.getResource(path).toURI()));
29+
return readFileAsString(InlineStaticResource.class.getResource(path).getPath());
3330
} catch (Exception e1) {
3431
try {
35-
return readFileAsString(Paths.get(path));
32+
return readFileAsString(path);
3633
} catch (Exception e2) {
3734
throw new RuntimeException("Couldn't find file with path='" + path + "'");
3835
}
3936
}
4037
}
4138

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();
4450
}
4551

4652
}

0 commit comments

Comments
 (0)