public static byte [ ] fileToBytes ( Object testClass , String relativePath ) { try { URL url = testClass . getClass ( ) . getResource ( relativePath ) ; if ( url == null ) { throw new FileNotFoundException ( relativePath ) ; } return Files . readAllBytes ( Paths . get ( url . toURI ( ) ) ) ; } catch ( IOException | URISyntaxException ex ) { throw new IllegalStateException ( ex ) ; } }
Helper method to convert a file to bytes .