Utils { public static byte[] readFile(File input) throws IOException { return Files.readAllBytes(Paths.get(input.getAbsolutePath())); } private  Utils(); static String generateParameterHash(String path, String func, List<String> args); static String generateDirectoryHash(String rootDir, String chaincodeDir, String hash); static byte[] generateTarGz(File sourceDirectory, String pathPrefix); static byte[] readFile(File input); static String generateUUID(); static Timestamp generateTimestamp(); static void deleteFileOrDirectory(File file); static byte[] hash(byte[] input, Digest digest); static String combinePaths(String first, String... other); static byte[] readFileFromClasspath(String fileName); static Properties parseGrpcUrl(String url); static Exception checkGrpcUrl(String url); static boolean isNullOrEmpty(String url); static String logString(final String string); static byte[] generateNonce(); static String toHexString(ByteString byteString); static String toHexString(byte[] bytes);  }
@Test public void testReadFile() throws Exception { byte[] expectedData = "TheQuickBrownFox".getBytes(); File tempFile = tempFolder.newFile("temp.txt"); Path file = Paths.get(tempFile.getAbsolutePath()); Files.write(file, expectedData); byte[] actualData = Utils.readFile(tempFile); Assert.assertArrayEquals(expectedData, actualData); }
@Test(expected = IOException.class) public void testReadFileNoFile() throws Exception { File rootDir = tempFolder.getRoot().getAbsoluteFile(); Utils.readFile(new File(rootDir, "temp.txt")); Assert.fail("Expected an IOException as the file does not exist"); }