Last active
January 1, 2016 20:39
-
-
Save elliottsj/8198330 to your computer and use it in GitHub Desktop.
For some reason, DiskLruCacheTest.java runs fine, but Main.java hangs before returning and doesn't write to the cache. EDIT: Fixed the issue by using Math.pow() instead of ^.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import junit.framework.Assert; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Test; | |
import java.io.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class DiskLruCacheTest { | |
@Test | |
public void testStoreArrayList() throws IOException { | |
// fixed: changed from 20 * 2^20 to (long) (20 * Math.pow(2, 20)) | |
DiskLruCache diskLruCache = DiskLruCache.open(new File("DiskLruCacheTest"), 1, 1, (long) (20 * Math.pow(2, 20))); | |
DiskLruCache.Editor editor = diskLruCache.edit("test-store-array-list"); | |
OutputStream os = editor.newOutputStream(0); | |
OutputStream bos = new BufferedOutputStream(os); | |
ObjectOutputStream oos = new ObjectOutputStream(bos); | |
List<String> list = new ArrayList<String>(); | |
list.add("first string"); | |
list.add("second string"); | |
oos.writeObject(list); | |
oos.close(); | |
editor.commit(); | |
diskLruCache.close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
// fixed: changed from 20 * 2^20 to (long) (20 * Math.pow(2, 20)) | |
DiskLruCache diskLruCache = DiskLruCache.open(new File("DiskLruCache"), 1, 1, (long) (20 * Math.pow(2, 20))); | |
DiskLruCache.Editor editor = diskLruCache.edit("test-store-array-list"); | |
OutputStream os = editor.newOutputStream(0); | |
OutputStream bos = new BufferedOutputStream(os); | |
ObjectOutputStream oos = new ObjectOutputStream(bos); | |
List<String> list = new ArrayList<String>(); | |
list.add("first string"); | |
list.add("second string"); | |
oos.writeObject(list); | |
oos.close(); | |
editor.commit(); | |
diskLruCache.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment