aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-03-12 15:51:17 +0100
committerlookshe <github@lookshe.org>2016-03-12 15:51:17 +0100
commit14c2c72bc1a00c8b9839047cdc73116e561ecd62 (patch)
treefe0828e9357d1876a0e3aa72ae13a2dad19718c4 /src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java
parent2a486c667a0c81772fcf125c5c3c9b49c78250e3 (diff)
parentdc26c95b40c3d0f48ed539f91e53c1bff1dceec6 (diff)
Merge branch 'trz/rebase' into trz/rename
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java b/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java
index a8375dc0..9b627f6b 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/FileUtils.java
@@ -147,4 +147,33 @@ public class FileUtils {
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
+
+ /**
+ * @param filename The filename to extract extension from
+ * @return last extension or empty string
+ */
+ public static String getLastExtension(final String filename) {
+ if (filename == null || filename.isEmpty()) {
+ return "";
+ }
+ final int lastDotPosition = filename.lastIndexOf('.');
+ final String lastPart = lastDotPosition != -1 ?
+ filename.substring(lastDotPosition + 1) : "";
+ return lastPart;
+ }
+
+ /**
+ * @param filename The filename to extract extension from
+ * @return second to last extension or empty string
+ */
+ public static String getSecondToLastExtension(final String filename) {
+ if (filename == null || filename.isEmpty()) {
+ return "";
+ }
+ final int lastDotPosition = filename.lastIndexOf('.');
+ final int secondToLastDotPosition = filename.lastIndexOf('.', lastDotPosition - 1);
+ final String secondToLastPart = secondToLastDotPosition != -1 ?
+ filename.substring(secondToLastDotPosition + 1, lastDotPosition) : "";
+ return secondToLastPart;
+ }
}