Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewTemplate.create(String) uses non-portable code to read template file, fails on Windows #4

Open
zelmak opened this issue Jun 16, 2019 · 1 comment

Comments

@zelmak
Copy link

zelmak commented Jun 16, 2019

Exception in thread "pool-1-thread-2" java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/Users/Brad/Projects/CleanCodeCaseStudy/target/test-classes/html/frontpage.html at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77) at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92) at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229) at java.base/java.nio.file.Path.of(Path.java:147) at java.base/java.nio.file.Paths.get(Paths.java:69) at cleancoderscom.view.ViewTemplate.create(ViewTemplate.java:13) at cleancoderscom.usecases.codecastSummaries.CodecastSummariesViewImpl.toHTML(CodecastSummariesViewImpl.java:13) at cleancoderscom.usecases.codecastSummaries.CodecastSummariesViewImpl.generateView(CodecastSummariesViewImpl.java:42) at cleancoderscom.usecases.codecastSummaries.CodecastSummariesController.handle(CodecastSummariesController.java:24) at cleancoderscom.http.Router.route(Router.java:20) at cleancoderscom.utilities.Main.lambda$main$0(Main.java:35) at cleancoderscom.socketserver.SocketServer$1$1.run(SocketServer.java:33) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834)

Not sure if you want a PR for this as it would have to apply to all the commits all the way down. :)

@zelmak
Copy link
Author

zelmak commented Jun 16, 2019

I fixed this by changing ViewTemplate.create:

    public static ViewTemplate create(String templateResource) throws IOException {
        try {
            ClassLoader classloader = Thread.currentThread().getContextClassLoader();
            String platformIndependentPath = Paths.get(classloader.getResource(templateResource).toURI()).toString();
            byte[] bytes = Files.readAllBytes(Paths.get(platformIndependentPath));
            return new ViewTemplate(new String(bytes));
        } catch (Exception e) {
            throw new IOException(e);
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant