FileUtils { public static String constructMediaPath(String formFilePath) { return getFormBasename(formFilePath) + MEDIA_SUFFIX; } private  FileUtils(); static String getMimeType(String fileUrl); static boolean createFolder(String path); static String getMd5Hash(File file); static String getMd5Hash(InputStream is); static Bitmap getBitmapScaledToDisplay(File file, int screenHeight, int screenWidth); static Bitmap getBitmapScaledToDisplay(File file, int screenHeight, int screenWidth, boolean upscaleEnabled); static String copyFile(File sourceFile, File destFile); static HashMap<String, String> parseXML(File xmlFile); static void deleteAndReport(File file); static String getFormBasename(File formXml); static String getFormBasename(String formFilePath); static String constructMediaPath(String formFilePath); static File getFormMediaDir(File formXml); static String getFormBasenameFromMediaFolder(File mediaFolder); static File getLastSavedFile(File formXml); static String getLastSavedPath(File mediaFolder); static String getOrCreateLastSavedSrc(File formXml); static void checkMediaPath(File mediaDir); static void purgeMediaPath(String mediaPath); static void moveMediaFiles(String tempMediaPath, File formMediaPath); static void saveBitmapToFile(Bitmap bitmap, String path); static Bitmap getBitmap(String path, BitmapFactory.Options originalOptions); static byte[] read(File file); static void write(File file, byte[] data); static int comparePaths(String a, String b); static String getFileExtension(String fileName); static void grantFilePermissions(Intent intent, Uri uri, Context context); static void grantFileReadPermissions(Intent intent, Uri uri, Context context); @SuppressWarnings("PMD.DoNotHardCodeSDCard") static File simplifyPath(File file); static Iterable<File> walk(File root); static Iterable<File> walkBreadthFirst(File root); static boolean isFileExists(File file); static boolean isFileExists(String filePath); static File getFileByPath(String filePath); static boolean deleteFile(final File file); static boolean deleteAllInDir(final File dir); static boolean deleteFilesInDirWithFilter(final File dir, final FileFilter filter); static boolean deleteDir(final File dir); static boolean createOrExistsDir(final File file); static boolean copyDir(final String srcDirPath,
                                  final String destDirPath); static final String VALID_FILENAME; static final String FORMID; static final String VERSION; static final String TITLE; static final String SUBMISSIONURI; static final String BASE64_RSA_PUBLIC_KEY; static final String AUTO_DELETE; static final String AUTO_SEND; static final String MEDIA_SUFFIX; static final String LAST_SAVED_FILENAME; }
@Test public void mediaDirNameIsCorrect() { String expected = "sample-file-media"; assertEquals(expected, FileUtils.constructMediaPath("sample-file.xml")); assertEquals(expected, FileUtils.constructMediaPath("sample-file.extension")); assertEquals(expected, FileUtils.constructMediaPath("sample-file.123")); assertEquals(expected, FileUtils.constructMediaPath("sample-file.docx")); }