Advertisement
Guest User

Simple HttpProxyCacheServer factory

a guest
Sep 9th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. /**
  2.  * <strong>Not thread-safe</strong> {@link HttpProxyCacheServer} factory that returns single instance of proxy.
  3.  *
  4.  * @author Alexey Danilov (danikula@gmail.com).
  5.  */
  6. public class ProxyFactory {
  7.  
  8.     private static HttpProxyCacheServer sharedProxy;
  9.  
  10.     private ProxyFactory() {
  11.     }
  12.  
  13.     public static HttpProxyCacheServer getProxy(Context context) {
  14.         return sharedProxy == null ? (sharedProxy = newProxy(context)) : sharedProxy;
  15.     }
  16.  
  17.     private static HttpProxyCacheServer newProxy(Context context) {
  18.         FileNameGenerator nameGenerator = new Md5FileNameGenerator(context.getExternalCacheDir());
  19.         return new HttpProxyCacheServer(nameGenerator);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement