FilesHelper { public static String getFileExtension(String name) { String ext; int lastDot = name.lastIndexOf('.'); int secondLastDot = name.lastIndexOf('.', lastDot - 1); if (secondLastDot > 0 ) { ext = name.substring(secondLastDot + 1); if (!ext.startsWith("tar")) { ext = name.substring(lastDot + 1); } } else if (lastDot > 0) { ext = name.substring(lastDot + 1); } else { ext = ""; } return ext; }  static String getFileExtension(String name); static String getFileExtension(File f); static String guessMimeType(File f); static String guessMimeType(String ext); static @NonNull String formatDate(long ms); static @NonNull String toRelativePath(File base, File f); static String toRelativePath(String base, File f); static @NonNull Folder makeRoot(String authority, StorageVolume volume); static @NonNull Folder makeFolder(String authority, StorageVolume volume, File dir); static @NonNull Track makeTrackFromFile(String authority, StorageVolume volume, File f); static long getFlags(@NonNull File f); static boolean deleteFile(File base, String relPath); static int deleteTrack(final Context context, final String id); static boolean deleteDirectory(Context context, File dir); static @NonNull List<File> filterAudioFiles(Context context, List<File> files); static @NonNull List<Track> convertAudioFilesToTracks(
            Context context, String authority, StorageVolume volume, List<File> audioFiles); static Track findTrack(Context context, String authority, StorageVolume volume, String id); static Track.Builder makeTrackFromCursor(String authority, StorageVolume volume, File f, Cursor c); static StorageVolume guessStorageVolume(Context context, List<StorageLookup.StorageVolume> volumes, String path); static void closeQuietly(Cursor c); static final boolean DUMPSTACKS; }
@Test public void testGetFileExtension() { File single = new File("/somepath/somefile.txt"); assertThat(getFileExtension(single)).isEqualTo("txt"); File douple = new File("/somepath/somefile.tar.gz"); assertThat(getFileExtension(douple)).isEqualTo("tar.gz"); File none = new File("/somepath/somefile"); assertThat(getFileExtension(none)).isEqualTo(""); File dots = new File("/somepath/somefile.with.dots.mp3"); assertThat(getFileExtension(dots)).isEqualTo("mp3"); File dotsdouble = new File("/somepath/samefile.with.dots.tar.gz"); assertThat(getFileExtension(dotsdouble)).isEqualTo("tar.gz"); File spaces = new File("/somepath/samefile with spaces.mp3"); assertThat(getFileExtension(spaces)).isEqualTo("mp3"); }