LargeFileUtils { public File saveDataToFile(DataHandler dh) throws IOException { File attachmentFile = generateAttachmentFile(); saveDataToFile(dh, attachmentFile); return attachmentFile; }  static LargeFileUtils getInstance(); boolean isParsePayloadAsFileLocationEnabled(); boolean isSavePayloadToFileEnabled(); URI parseBase64DataAsUri(DataHandler dh); File saveDataToFile(DataHandler dh); void saveDataToFile(DataHandler dh, File file); void closeStreamWithoutException(InputStream is); void closeStreamWithoutException(OutputStream os); DataHandler convertToDataHandler(File file); DataHandler convertToDataHandler(String data); DataHandler convertToDataHandler(byte[] data); byte[] convertToBytes(DataHandler dh); File generateAttachmentFile(); File generateAttachmentFile(String payloadSaveDirectory);  }
@Test public void testSaveDataToFile() throws Exception { String RANDOM_DATA = "1234567890"; LargeFileUtils fileUtils = new LargeFileUtils(); File tempFile = File.createTempFile("temp", ".tmp"); tempFile.deleteOnExit(); DataHandler dh = fileUtils.convertToDataHandler(RANDOM_DATA); fileUtils.saveDataToFile(dh, tempFile); assertTrue(tempFile.exists()); assertTrue(tempFile.length() > 0); byte[] dataBytes = fileUtils.convertToBytes(dh); String string = new String(dataBytes); assertEquals(string, RANDOM_DATA); }