private static StartupEntry readFile ( String filename , String context , MessageHandler mh ) { if ( filename != null ) { try { byte [ ] encoded = Files . readAllBytes ( toPathResolvingUserHome ( filename ) ) ; return new StartupEntry ( false , filename , new String ( encoded ) , LocalDateTime . now ( ) . format ( DateTimeFormatter . ofLocalizedDateTime ( FormatStyle . MEDIUM ) ) ) ; } catch ( AccessDeniedException e ) { mh . errormsg ( "jshell.err.file.not.accessible" , context , filename , e . getMessage ( ) ) ; } catch ( NoSuchFileException e ) { String resource = getResource ( filename ) ; if ( resource != null ) { // Not found as file, but found as resource return new StartupEntry ( true , filename , resource ) ; } mh . errormsg ( "jshell.err.file.not.found" , context , filename ) ; } catch ( Exception e ) { mh . errormsg ( "jshell.err.file.exception" , context , filename , e ) ; } } else { mh . errormsg ( "jshell.err.file.filename" , context ) ; } return null ; }
Read a external file or a resource .