Java tutorial
//package com.java2s; //License from project: Open Source License import android.net.Uri; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLDecoder; import java.util.List; public class Main { private static final String[] MASK_HOSTS_SEG = { "l.php", null, null, "url", "away.php", null, "attribution_link", "api", "rewrite.php", null, "api", "attribution_link" }; private static final String[] MASK_HOSTS_PAR = { "u", "url", "out", "q", "to", "RD_PARM1", "u", "out", "url", "url", "out", "a" }; /** * Unmask the URI and return it */ public static Uri unmaskLink(Uri uri, int i) { String s = null; List pathSegments; if (MASK_HOSTS_SEG[i] == null) { // The host always masks, no need to determine if it's the right segment s = uri.getQueryParameter(MASK_HOSTS_PAR[i]); } else { // Only a certain segment is used to mask URLs. Determine if this is it. pathSegments = uri.getPathSegments(); if (pathSegments == null) return uri; // If it is, unmask the URL. if (pathSegments.size() > 0 && MASK_HOSTS_SEG[i].equals(pathSegments.get(0))) s = uri.getQueryParameter(MASK_HOSTS_PAR[i]); } if (s == null) return uri; // Resolve link if it's relative try { if (!new URI(s).isAbsolute()) s = new URI(uri.toString()).resolve(s).toString(); } catch (URISyntaxException e) { e.printStackTrace(); } try { return Uri.parse(URLDecoder.decode(s, "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return uri; } } }