/** * Saves media data downloaded from an API in {@code byte[]} format into a * file on the file system. * * @param mediaData the media data {@code byte[]} to store on the file system * @param fileName the name of the file on the file system to save the media * data into * @throws FileNotFoundException if the file exists but is a directory, does * not exist but cannot be created, or cannot be opened for any reason * @throws IOException if the file cannot be written to */ public static void saveMediaDataToFile(byte[] mediaData, String fileName) throws FileNotFoundException, IOException { saveMediaDataToFile(mediaData, new File(fileName)); }
/** * Saves media data downloaded from an API in {@code byte[]} format into a * file on the file system. * * @param mediaData the media data {@code byte[]} to store on the file system * @param fileName the name of the file on the file system to save the media * data into * @throws FileNotFoundException if the file exists but is a directory, does * not exist but cannot be created, or cannot be opened for any reason * @throws IOException if the file cannot be written to */ public static void saveMediaDataToFile(byte[] mediaData, String fileName) throws FileNotFoundException, IOException { saveMediaDataToFile(mediaData, new File(fileName)); }
@Test public void testSaveMediaDataToFile_stringArg() throws IOException { File outputFile = tempFolder.newFile(); Media.saveMediaDataToFile(TEST_DATA, outputFile.getPath()); FileInputStream inputStream = new FileInputStream(outputFile); byte[] actualBytes; try { actualBytes = ByteStreams.toByteArray(inputStream); } finally { inputStream.close(); } assertArrayEquals(TEST_DATA, actualBytes); }
@Test public void testSaveMediaDataToFile_fileArg() throws IOException { File outputFile = tempFolder.newFile(); Media.saveMediaDataToFile(TEST_DATA, outputFile); FileInputStream inputStream = new FileInputStream(outputFile); byte[] actualBytes; try { actualBytes = ByteStreams.toByteArray(inputStream); } finally { inputStream.close(); } assertArrayEquals(TEST_DATA, actualBytes); } }