X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2FProxy.java;h=750b3eef6a37c874b69b485e8f30b9c41ca47946;hp=f6ce11b3666bf05e83aadab852219ecdc4867832;hb=HEAD;hpb=94c44e42bf9d13fb372733318d9667c35af266be diff --git a/src/be/nikiroo/utils/Proxy.java b/src/be/nikiroo/utils/Proxy.java old mode 100755 new mode 100644 index f6ce11b..750b3ee --- a/src/be/nikiroo/utils/Proxy.java +++ b/src/be/nikiroo/utils/Proxy.java @@ -9,6 +9,64 @@ import java.net.PasswordAuthentication; * @author niki */ public class Proxy { + /** + * Use the proxy described by this string: + * + * Some examples: + * + * + * @param proxy + * the proxy + */ + static public void use(String proxy) { + if (proxy != null && !proxy.isEmpty()) { + String user = null; + String password = null; + int port = 8080; + + if (proxy.contains("@")) { + int pos = proxy.indexOf("@"); + user = proxy.substring(0, pos); + proxy = proxy.substring(pos + 1); + if (user.contains(":")) { + pos = user.indexOf(":"); + password = user.substring(pos + 1); + user = user.substring(0, pos); + } + } + + if (proxy.equals(":")) { + proxy = null; + } else if (proxy.contains(":")) { + int pos = proxy.indexOf(":"); + try { + port = Integer.parseInt(proxy.substring(0, pos)); + proxy = proxy.substring(pos + 1); + } catch (Exception e) { + } + } + + if (proxy == null) { + Proxy.useSystemProxy(user, password); + } else { + Proxy.useProxy(proxy, port, user, password); + } + } + } + /** * Use the system proxy. */