aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/utils/FileUtils.java
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-04-24 14:03:03 +0200
committerSamuel Tardieu <sam@rfc1149.net>2014-04-24 14:05:06 +0200
commitd9c10378ffb456f2337739d1df316826913a2490 (patch)
tree4f80e8308bcdf00d7808997da1fc026c6c3b9ec8 /main/src/cgeo/geocaching/utils/FileUtils.java
parent34a31ce931c8e88f0e4e02897e910c42c4b14ae5 (diff)
downloadcgeo-d9c10378ffb456f2337739d1df316826913a2490.zip
cgeo-d9c10378ffb456f2337739d1df316826913a2490.tar.gz
cgeo-d9c10378ffb456f2337739d1df316826913a2490.tar.bz2
refactoring: add conversion utility methods between File and url
Diffstat (limited to 'main/src/cgeo/geocaching/utils/FileUtils.java')
-rw-r--r--main/src/cgeo/geocaching/utils/FileUtils.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/utils/FileUtils.java b/main/src/cgeo/geocaching/utils/FileUtils.java
index 4a349a8..de068fd 100644
--- a/main/src/cgeo/geocaching/utils/FileUtils.java
+++ b/main/src/cgeo/geocaching/utils/FileUtils.java
@@ -153,4 +153,32 @@ public final class FileUtils {
}
return true;
}
+
+ /**
+ * Check if the URL represents a file on the local file system.
+ *
+ * @return <tt>true</tt> if the URL scheme is <tt>file</tt>, <tt>false</tt> otherwise
+ */
+ public static boolean isFileUrl(final String url) {
+ return StringUtils.startsWith(url, "file://");
+ }
+
+ /**
+ * Build an URL from a file name.
+ *
+ * @param file a local file name
+ * @return an URL with the <tt>file</tt> scheme
+ */
+ public static String fileToUrl(final File file) {
+ return "file://" + file.getAbsolutePath();
+ }
+
+ /**
+ * Local file name when {@link #isLocalFile()} is <tt>true</tt>.
+ *
+ * @return the local file
+ */
+ public static File urlToFile(final String url) {
+ return new File(StringUtils.substring(url, 7));
+ }
}