private static Reader readerFromUrl ( String resourceName ) throws IOException { URL resourceUrl = TemplateVars . class . getResource ( resourceName ) ; InputStream in ; try { if ( resourceUrl . getProtocol ( ) . equalsIgnoreCase ( "file" ) ) { in = inputStreamFromFile ( resourceUrl ) ; } else if ( resourceUrl . getProtocol ( ) . equalsIgnoreCase ( "jar" ) ) { in = inputStreamFromJar ( resourceUrl ) ; } else { throw new AssertionError ( "Template fallback logic fails for: " + resourceUrl ) ; } } catch ( URISyntaxException e ) { throw new IOException ( e ) ; } return new InputStreamReader ( in , StandardCharsets . UTF_8 ) ; }
through the getResourceAsStream should be a lot more efficient than reopening the jar .