How to send directly InputStream as response through handler
Previously, I am using below code to render a html file from handler
ClassLoader classLoader = this.getClass().getClassLoader();
File file = new File(classLoader.getResource("raml/api.html").getFile());
But now we are moving to jar from war, so it can't able to find api.html file. After some time spend on internet I come to know that we can't use getResource() to read file within jar file we have to use getResourceAsStream().
So I have written below code to render html file withing jar. Its working fine.
InputStream is = this.getClass().getResourceAsStream("/raml/api.html");
byte buffer = new byte[is.available()];
File targetFile = new File("/raml/api1.html");
Here, the flow is File -> InputStream -> File But I think its not good solution.
Is there any better way in ratpack to send directly InputStream as response through handler?