summaryrefslogtreecommitdiff
path: root/src/de/danoeh/antennapod/util/URIUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/danoeh/antennapod/util/URIUtil.java')
-rw-r--r--src/de/danoeh/antennapod/util/URIUtil.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/de/danoeh/antennapod/util/URIUtil.java b/src/de/danoeh/antennapod/util/URIUtil.java
new file mode 100644
index 000000000..5af40d591
--- /dev/null
+++ b/src/de/danoeh/antennapod/util/URIUtil.java
@@ -0,0 +1,35 @@
+package de.danoeh.antennapod.util;
+
+import android.util.Log;
+import de.danoeh.antennapod.BuildConfig;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+/**
+ * Utility methods for dealing with URL encoding.
+ */
+public class URIUtil {
+ private static final String TAG = "URIUtil";
+
+ private URIUtil() {}
+
+ public static URI getURIFromRequestUrl(String source) {
+ // try without encoding the URI
+ try {
+ return new URI(source);
+ } catch (URISyntaxException e) {
+ if (BuildConfig.DEBUG) Log.d(TAG, "Source is not encoded, encoding now");
+ }
+ try {
+ URL url = new URL(source);
+ return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+}