Skip to content

Commit

Permalink
Add already-implemented interfaces Closeable and Flushable to the cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Jan 3, 2016
1 parent ee83d8d commit d662c1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions okhttp/src/main/java/okhttp3/Cache.java
Expand Up @@ -16,7 +16,9 @@

package okhttp3;

import java.io.Closeable;
import java.io.File;
import java.io.Flushable;
import java.io.IOException;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
Expand Down Expand Up @@ -131,7 +133,7 @@
* caching directives. It even offers convenient constants {@link CacheControl#FORCE_NETWORK} and
* {@link CacheControl#FORCE_CACHE} that address the use cases above.
*/
public final class Cache {
public final class Cache implements Closeable, Flushable {
private static final int VERSION = 201105;
private static final int ENTRY_METADATA = 0;
private static final int ENTRY_BODY = 1;
Expand Down Expand Up @@ -380,11 +382,11 @@ public long maxSize() {
return cache.getMaxSize();
}

public void flush() throws IOException {
@Override public void flush() throws IOException {
cache.flush();
}

public void close() throws IOException {
@Override public void close() throws IOException {
cache.close();
}

Expand Down
7 changes: 4 additions & 3 deletions okhttp/src/main/java/okhttp3/internal/DiskLruCache.java
Expand Up @@ -20,6 +20,7 @@
import java.io.EOFException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.Flushable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -81,7 +82,7 @@
* value, the edit will fail silently. Callers should handle other problems by catching {@code
* IOException} and responding appropriately.
*/
public final class DiskLruCache implements Closeable {
public final class DiskLruCache implements Closeable, Flushable {
static final String JOURNAL_FILE = "journal";
static final String JOURNAL_FILE_TEMP = "journal.tmp";
static final String JOURNAL_FILE_BACKUP = "journal.bkp";
Expand Down Expand Up @@ -623,7 +624,7 @@ private synchronized void checkNotClosed() {
}

/** Force buffered operations to the filesystem. */
public synchronized void flush() throws IOException {
@Override public synchronized void flush() throws IOException {
if (!initialized) return;

checkNotClosed();
Expand All @@ -632,7 +633,7 @@ public synchronized void flush() throws IOException {
}

/** Closes this cache. Stored values will remain on the filesystem. */
public synchronized void close() throws IOException {
@Override public synchronized void close() throws IOException {
if (!initialized || closed) {
closed = true;
return;
Expand Down

0 comments on commit d662c1a

Please sign in to comment.