Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added missing @OverRide annotations
  • Loading branch information
Stefano Dacchille committed Apr 24, 2012
1 parent dc3ea96 commit 2a9cc0f
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 27 deletions.
Expand Up @@ -70,7 +70,7 @@ public abstract class AbstractCache<KeyT, ValT> implements Map<KeyT, ValT> {
private ConcurrentMap<KeyT, ValT> cache;

private String name;

private long expirationInMinutes;

/**
Expand All @@ -93,7 +93,7 @@ public AbstractCache(String name, int initialCapacity, long expirationInMinutes,

this.name = name;
this.expirationInMinutes = expirationInMinutes;

MapMaker mapMaker = new MapMaker();
mapMaker.initialCapacity(initialCapacity);
mapMaker.expiration(expirationInMinutes * 60, TimeUnit.SECONDS);
Expand All @@ -108,19 +108,19 @@ public AbstractCache(String name, int initialCapacity, long expirationInMinutes,
private void sanitizeDiskCache() {
List<File> cachedFiles = getCachedFiles();
for (File f : cachedFiles) {
// if file older than expirationInMinutes, remove it
long lastModified = f.lastModified();
Date now = new Date();
long ageInMinutes = ((now.getTime() - lastModified) / (1000*60));
if (ageInMinutes >= expirationInMinutes) {
Log.d(name, "DISK cache expiration for file " + f.toString());
f.delete();
}
// if file older than expirationInMinutes, remove it
long lastModified = f.lastModified();
Date now = new Date();
long ageInMinutes = ((now.getTime() - lastModified) / (1000 * 60));

if (ageInMinutes >= expirationInMinutes) {
Log.d(name, "DISK cache expiration for file " + f.toString());
f.delete();
}
}
}
}

/**
/**
* Enable caching to the phone's internal storage or SD card.
*
* @param context
Expand All @@ -137,8 +137,8 @@ public boolean enableDiskCache(Context context, int storageDevice) {
if (storageDevice == DISK_CACHE_SDCARD
&& Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
// SD-card available
rootDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/"
+ appContext.getPackageName() + "/cache";
rootDir = Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/Android/data/" + appContext.getPackageName() + "/cache";
} else {
File internalCacheDir = appContext.getCacheDir();
// apparently on some configurations this can come back as null
Expand Down Expand Up @@ -251,6 +251,7 @@ private File getFileForKey(KeyT key) {
* the cache key
* @return the cached value, or null if element was not cached
*/
@Override
@SuppressWarnings("unchecked")
public synchronized ValT get(Object elementKey) {
KeyT key = (KeyT) elementKey;
Expand All @@ -264,18 +265,18 @@ public synchronized ValT get(Object elementKey) {
// memory miss, try reading from disk
File file = getFileForKey(key);
if (file.exists()) {
// if file older than expirationInMinutes, remove it
long lastModified = file.lastModified();
Date now = new Date();
long ageInMinutes = ((now.getTime() - lastModified) / (1000*60));
if (ageInMinutes >= expirationInMinutes) {
Log.d(name, "DISK cache expiration for file " + file.toString());
file.delete();
return null;
}
// disk hit
// if file older than expirationInMinutes, remove it
long lastModified = file.lastModified();
Date now = new Date();
long ageInMinutes = ((now.getTime() - lastModified) / (1000 * 60));

if (ageInMinutes >= expirationInMinutes) {
Log.d(name, "DISK cache expiration for file " + file.toString());
file.delete();
return null;
}

// disk hit
Log.d(name, "DISK cache hit for " + key.toString());
try {
value = readValueFromDisk(file);
Expand All @@ -299,6 +300,7 @@ public synchronized ValT get(Object elementKey) {
* Writes an element to the cache. NOTE: If disk caching is enabled, this will write through to
* the disk, which may introduce a performance penalty.
*/
@Override
public synchronized ValT put(KeyT key, ValT value) {
if (isDiskCacheEnabled) {
cacheToDisk(key, value);
Expand All @@ -307,6 +309,7 @@ public synchronized ValT put(KeyT key, ValT value) {
return cache.put(key, value);
}

@Override
public synchronized void putAll(Map<? extends KeyT, ? extends ValT> t) {
throw new UnsupportedOperationException();
}
Expand All @@ -319,6 +322,7 @@ public synchronized void putAll(Map<? extends KeyT, ? extends ValT> t) {
* the cache key
* @return true if the value is cached in memory or on disk, false otherwise
*/
@Override
public synchronized boolean containsKey(Object key) {
return cache.containsKey(key) || containsKeyOnDisk(key);
}
Expand Down Expand Up @@ -351,13 +355,15 @@ public synchronized boolean containsKeyOnDisk(Object key) {
* Checks if the given value is currently held in memory. For performance reasons, this method
* does NOT probe the disk cache.
*/
@Override
public synchronized boolean containsValue(Object value) {
return cache.containsValue(value);
}

/**
* Removes an entry from both memory and disk.
*/
@Override
@SuppressWarnings("unchecked")
public synchronized ValT remove(Object key) {
ValT value = removeKey(key);
Expand All @@ -383,18 +389,22 @@ public ValT removeKey(Object key) {
return cache.remove(key);
}

@Override
public Set<KeyT> keySet() {
return cache.keySet();
}

@Override
public Set<Map.Entry<KeyT, ValT>> entrySet() {
return cache.entrySet();
}

@Override
public synchronized int size() {
return cache.size();
}

@Override
public synchronized boolean isEmpty() {
return cache.isEmpty();
}
Expand Down Expand Up @@ -435,6 +445,7 @@ public void setDiskCacheEnabled(String rootDir) {
/**
* Clears the entire cache (memory and disk).
*/
@Override
public synchronized void clear() {
clear(isDiskCacheEnabled);
}
Expand Down Expand Up @@ -462,6 +473,7 @@ public synchronized void clear(boolean removeFromDisk) {
Log.d(LOG_TAG, "Cache cleared");
}

@Override
public Collection<ValT> values() {
return cache.values();
}
Expand Down
Expand Up @@ -62,19 +62,23 @@ public abstract class IgnitedHttpRequestBase implements IgnitedHttpRequest,
this.httpClient = http.getHttpClient();
}

@Override
public HttpUriRequest unwrap() {
return request;
}

@Override
public String getRequestUrl() {
return request.getURI().toString();
}

@Override
public IgnitedHttpRequestBase expecting(Integer... statusCodes) {
expectedStatusCodes.addAll(Arrays.asList(statusCodes));
return this;
}

@Override
public IgnitedHttpRequestBase retries(int retries) {
if (retries < 0) {
this.maxRetries = 0;
Expand All @@ -86,6 +90,7 @@ public IgnitedHttpRequestBase retries(int retries) {
return this;
}

@Override
public IgnitedHttpRequest withTimeout(int timeout) {
oldSocketTimeout = httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT,
IgnitedHttp.DEFAULT_SOCKET_TIMEOUT);
Expand All @@ -100,6 +105,7 @@ public IgnitedHttpRequest withTimeout(int timeout) {
return this;
}

@Override
public IgnitedHttpResponse send() throws ConnectException {

IgnitedHttpRequestRetryHandler retryHandler = new IgnitedHttpRequestRetryHandler(maxRetries);
Expand Down Expand Up @@ -151,6 +157,7 @@ private boolean retryRequest(IgnitedHttpRequestRetryHandler retryHandler, IOExce
return retryHandler.retryRequest(cause, ++executionCount, context);
}

@Override
public IgnitedHttpResponse handleResponse(HttpResponse response) throws IOException {
int status = response.getStatusLine().getStatusCode();
if (expectedStatusCodes != null && !expectedStatusCodes.isEmpty()
Expand Down
Expand Up @@ -47,6 +47,7 @@ public IgnitedHttpRequestRetryHandler(int maxRetries) {
this.maxRetries = maxRetries;
}

@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
boolean retry;

Expand Down
Expand Up @@ -36,26 +36,32 @@ public IgnitedHttpResponseImpl(HttpResponse response) throws IOException {
}
}

@Override
public HttpResponse unwrap() {
return response;
}

@Override
public InputStream getResponseBody() throws IOException {
return entity.getContent();
}

@Override
public byte[] getResponseBodyAsBytes() throws IOException {
return EntityUtils.toByteArray(entity);
}

@Override
public String getResponseBodyAsString() throws IOException {
return EntityUtils.toString(entity);
}

@Override
public int getStatusCode() {
return this.response.getStatusLine().getStatusCode();
}

@Override
public String getHeader(String header) {
if (!response.containsHeader(header)) {
return null;
Expand Down
Expand Up @@ -18,26 +18,32 @@ public CachedHttpRequest(HttpResponseCache responseCache, String url) {
this.url = url;
}

@Override
public String getRequestUrl() {
return url;
}

@Override
public IgnitedHttpRequest expecting(Integer... statusCodes) {
return this;
}

@Override
public IgnitedHttpRequest retries(int retries) {
return this;
}

@Override
public IgnitedHttpResponse send() throws ConnectException {
return new CachedHttpResponse(responseCache.get(url));
}

@Override
public HttpUriRequest unwrap() {
return null;
}

@Override
public IgnitedHttpRequest withTimeout(int timeout) {
return this;
}
Expand Down
Expand Up @@ -39,26 +39,32 @@ public CachedHttpResponse(ResponseData cachedData) {
this.cachedData = cachedData;
}

@Override
public String getHeader(String header) {
return null;
}

@Override
public InputStream getResponseBody() throws IOException {
return new ByteArrayInputStream(cachedData.responseBody);
}

@Override
public byte[] getResponseBodyAsBytes() throws IOException {
return cachedData.responseBody;
}

@Override
public String getResponseBodyAsString() throws IOException {
return new String(cachedData.responseBody);
}

@Override
public int getStatusCode() {
return cachedData.statusCode;
}

@Override
public HttpResponse unwrap() {
return null;
}
Expand Down
Expand Up @@ -67,6 +67,7 @@ private SSLContext getSSLContext() throws IOException {
* @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,
* java.lang.String, int, java.net.InetAddress, int, org.apache.http.params.HttpParams)
*/
@Override
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress,
int localPort, HttpParams params) throws IOException, UnknownHostException,
ConnectTimeoutException {
Expand Down Expand Up @@ -94,13 +95,15 @@ public Socket connectSocket(Socket sock, String host, int port, InetAddress loca
/**
* @see org.apache.http.conn.scheme.SocketFactory#createSocket()
*/
@Override
public Socket createSocket() throws IOException {
return getSSLContext().getSocketFactory().createSocket();
}

/**
* @see org.apache.http.conn.scheme.SocketFactory#isSecure(java.net.Socket)
*/
@Override
public boolean isSecure(Socket socket) throws IllegalArgumentException {
return true;
}
Expand All @@ -109,6 +112,7 @@ public boolean isSecure(Socket socket) throws IllegalArgumentException {
* @see org.apache.http.conn.scheme.LayeredSocketFactory#createSocket(java.net.Socket,
* java.lang.String, int, boolean)
*/
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
throws IOException, UnknownHostException {
return getSSLContext().getSocketFactory().createSocket();
Expand All @@ -120,10 +124,12 @@ public Socket createSocket(Socket socket, String host, int port, boolean autoClo
// for the correct operation of some connection managers
// -------------------------------------------------------------------

@Override
public boolean equals(Object obj) {
return ((obj != null) && obj.getClass().equals(EasySSLSocketFactory.class));
}

@Override
public int hashCode() {
return EasySSLSocketFactory.class.hashCode();
}
Expand Down
Expand Up @@ -8,14 +8,17 @@
// used to work around a bug in Android 1.6:
// http://code.google.com/p/android/issues/detail?id=1946
public class TrivialTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}

@Override
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}

@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
Expand Down

0 comments on commit 2a9cc0f

Please sign in to comment.