### Question:
ScriptUtil { public byte[] getFileBytes(String fileName) { File file = new File(fileName); long length = file.length(); if (length > Integer.MAX_VALUE) { throw new IllegalArgumentException("Can not read file larger than " + Integer.MAX_VALUE + " byte: " + fileName); } byte[] bytes; InputStream is = null; try { bytes = new byte[(int) length]; is = new FileInputStream(file); int offset = 0, bytesRead = 0; for (offset = 0, bytesRead = 0; offset < bytes.length && bytesRead >= 0; offset += bytesRead) { bytesRead = is.read(bytes, offset, bytes.length - offset); } if (offset < bytes.length) { throw new RuntimeException("Could not read entire file " + file.getName() + ", only " + offset + " of " + bytes.length + " bytes read"); } } catch (IOException ioe) { throw new RuntimeException("Error reading file: " + ioe.getMessage()); } finally { try { if (is != null) { is.close(); } } catch (IOException ioe) { throw new RuntimeException("Error closing file: " + ioe.getMessage()); } } return bytes; } ScriptUtil(RhqFacade remoteClient); @NoTopLevelIndirection void init(ScriptEngine scriptEngine); @Deprecated PageList<Resource> findResources(String string); void saveBytesToFile(byte[] bytes, String filename); byte[] getFileBytes(String fileName); void sleep(long millis); ResourceOperationHistory waitForScheduledOperationToComplete(ResourceOperationSchedule schedule); ResourceOperationHistory waitForScheduledOperationToComplete(ResourceOperationSchedule schedule,
                                                                        long intervalDuration,
                                                                        int maxIntervals); boolean isDefined(String identifier); String uploadContent(String filename);  }### Answer:
@Test public void getFileBytes() { ScriptUtil scriptUtil = new ScriptUtil(null); try { String fileContents = "the rain in spain falls mainly on the plain"; String tempDir = System.getProperty("java.io.tmpdir"); File testFile = new File(tempDir, "getFileBytesTest.txt"); byte[] contentBytes = fileContents.getBytes(); FileOutputStream writer = new FileOutputStream(testFile); writer.write(contentBytes); writer.close(); System.out.println("Test data written to " + testFile.getAbsolutePath()); byte[] fileBytes = scriptUtil.getFileBytes(testFile.getAbsolutePath()); String results = new String(fileBytes); System.out.println("Wrote: \"" + fileContents + "\"\nRead: \"" + results + "\""); assert fileContents.equals(results) : "Wrote: \"" + fileContents + "\"\nRead: \"" + results + "\""; } catch (IOException ioe) { assert false : "Failure testing getFileBytes: " + ioe.getMessage(); } }