Merge "Fix broken DiskBasedCache"
diff --git a/src/main/java/com/android/volley/toolbox/DiskBasedCache.java b/src/main/java/com/android/volley/toolbox/DiskBasedCache.java
index 036b55a..ff687d6 100644
--- a/src/main/java/com/android/volley/toolbox/DiskBasedCache.java
+++ b/src/main/java/com/android/volley/toolbox/DiskBasedCache.java
@@ -62,7 +62,7 @@
     private static final float HYSTERESIS_FACTOR = 0.9f;
 
     /** Magic number for current version of cache file format. */
-    private static final int CACHE_MAGIC = 0x20140623;
+    private static final int CACHE_MAGIC = 0x20150306;
 
     /**
      * Constructs an instance of the DiskBasedCache at the specified directory.
@@ -397,16 +397,11 @@
                 entry.etag = null;
             }
             entry.serverDate = readLong(is);
+            entry.lastModified = readLong(is);
             entry.ttl = readLong(is);
             entry.softTtl = readLong(is);
             entry.responseHeaders = readStringStringMap(is);
 
-            try {
-                entry.lastModified = readLong(is);
-            } catch (EOFException e) {
-                // the old cache entry format doesn't know lastModified
-            }
-
             return entry;
         }
 
@@ -435,10 +430,10 @@
                 writeString(os, key);
                 writeString(os, etag == null ? "" : etag);
                 writeLong(os, serverDate);
+                writeLong(os, lastModified);
                 writeLong(os, ttl);
                 writeLong(os, softTtl);
                 writeStringStringMap(responseHeaders, os);
-                writeLong(os, lastModified);
                 os.flush();
                 return true;
             } catch (IOException e) {
diff --git a/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java b/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java
index bf1d258..0a8be77 100644
--- a/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java
+++ b/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java
@@ -125,45 +125,6 @@
         assertEquals(DiskBasedCache.readStringStringMap(bais), emptyValue);
     }
 
-    /** deserializing the old format into the new one. */
-    @Test public void testCacheHeaderSerializationOldToNewFormat() throws Exception {
-
-        final int CACHE_MAGIC = 0x20140623;
-        final String key = "key";
-        final String etag = "etag";
-        final long serverDate = 1234567890l;
-        final long ttl = 1357924680l;
-        final long softTtl = 2468013579l;
-
-        Map<String, String> responseHeaders = new HashMap<String, String>();
-        responseHeaders.put("first", "thing");
-        responseHeaders.put("second", "item");
-
-        // write old sytle header (without lastModified)
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        DiskBasedCache.writeInt(baos, CACHE_MAGIC);
-        DiskBasedCache.writeString(baos, key);
-        DiskBasedCache.writeString(baos, etag == null ? "" : etag);
-        DiskBasedCache.writeLong(baos, serverDate);
-        DiskBasedCache.writeLong(baos, ttl);
-        DiskBasedCache.writeLong(baos, softTtl);
-        DiskBasedCache.writeStringStringMap(responseHeaders, baos);
-
-        // read / test new style header (with lastModified)
-        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-        CacheHeader cacheHeader = CacheHeader.readHeader(bais);
-
-        assertEquals(cacheHeader.key, key);
-        assertEquals(cacheHeader.etag, etag);
-        assertEquals(cacheHeader.serverDate, serverDate);
-        assertEquals(cacheHeader.ttl, ttl);
-        assertEquals(cacheHeader.softTtl, softTtl);
-        assertEquals(cacheHeader.responseHeaders, responseHeaders);
-
-        // the old format doesn't know lastModified
-        assertEquals(cacheHeader.lastModified, 0);
-    }
-
     @Test
     public void publicMethods() throws Exception {
         // Catch-all test to find API-breaking changes.