static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
@Test public void serializeInt() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DiskBasedCache.writeInt(baos, 0); DiskBasedCache.writeInt(baos, 19791214); DiskBasedCache.writeInt(baos, -20050711); DiskBasedCache.writeInt(baos, Integer.MIN_VALUE); DiskBasedCache.writeInt(baos, Integer.MAX_VALUE); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); assertEquals(DiskBasedCache.readInt(bais), 0); assertEquals(DiskBasedCache.readInt(bais), 19791214); assertEquals(DiskBasedCache.readInt(bais), -20050711); assertEquals(DiskBasedCache.readInt(bais), Integer.MIN_VALUE); assertEquals(DiskBasedCache.readInt(bais), Integer.MAX_VALUE); }
@Test public void serializeInt() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DiskBasedCache.writeInt(baos, 0); DiskBasedCache.writeInt(baos, 19791214); DiskBasedCache.writeInt(baos, -20050711); DiskBasedCache.writeInt(baos, Integer.MIN_VALUE); DiskBasedCache.writeInt(baos, Integer.MAX_VALUE); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); assertEquals(DiskBasedCache.readInt(bais), 0); assertEquals(DiskBasedCache.readInt(bais), 19791214); assertEquals(DiskBasedCache.readInt(bais), -20050711); assertEquals(DiskBasedCache.readInt(bais), Integer.MIN_VALUE); assertEquals(DiskBasedCache.readInt(bais), Integer.MAX_VALUE); }
/** * Reads the header off of an InputStream and returns a CacheHeader object. * @param is The InputStream to read from. * @throws java.io.IOException */ public static CacheHeader readHeader(InputStream is) throws IOException { CacheHeader entry = new CacheHeader(); int magic = readInt(is); if (magic != CACHE_MAGIC) { // don't bother deleting, it'll get pruned eventually throw new IOException(); } entry.key = readString(is); entry.etag = readString(is); if (entry.etag.equals("")) { entry.etag = null; } entry.serverDate = readLong(is); entry.lastModified = readLong(is); entry.ttl = readLong(is); entry.softTtl = readLong(is); entry.responseHeaders = readStringStringMap(is); return entry; }
/** * Reads the header off of an InputStream and returns a CacheHeader object. * @param is The InputStream to read from. * @throws IOException */ public static CacheHeader readHeader(InputStream is) throws IOException { CacheHeader entry = new CacheHeader(); int magic = readInt(is); if (magic != CACHE_MAGIC) { // don't bother deleting, it'll get pruned eventually throw new IOException(); } entry.key = readString(is); entry.etag = readString(is); if (entry.etag.equals("")) { entry.etag = null; } entry.serverDate = readLong(is); entry.lastModified = readLong(is); entry.ttl = readLong(is); entry.softTtl = readLong(is); entry.responseHeaders = readStringStringMap(is); return entry; }
/** * Reads the header off of an InputStream and returns a CacheHeader object. * @param is The InputStream to read from. * @throws IOException */ public static CacheHeader readHeader(InputStream is) throws IOException { CacheHeader entry = new CacheHeader(); int magic = readInt(is); if (magic != CACHE_MAGIC) { // don't bother deleting, it'll get pruned eventually throw new IOException(); } entry.key = readString(is); entry.etag = readString(is); if (entry.etag.equals("")) { entry.etag = null; } entry.serverDate = readLong(is); entry.lastModified = readLong(is); entry.ttl = readLong(is); entry.softTtl = readLong(is); entry.responseHeaders = readStringStringMap(is); return entry; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
static Map<String, String> readStringStringMap(InputStream is) throws IOException { int size = readInt(is); Map<String, String> result = (size == 0) ? Collections.<String, String>emptyMap() : new HashMap<String, String>(size); for (int i = 0; i < size; i++) { String key = readString(is).intern(); String value = readString(is).intern(); result.put(key, value); } return result; }
@Test public void serializeInt() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DiskBasedCache.writeInt(baos, 0); DiskBasedCache.writeInt(baos, 19791214); DiskBasedCache.writeInt(baos, -20050711); DiskBasedCache.writeInt(baos, Integer.MIN_VALUE); DiskBasedCache.writeInt(baos, Integer.MAX_VALUE); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); assertEquals(DiskBasedCache.readInt(bais), 0); assertEquals(DiskBasedCache.readInt(bais), 19791214); assertEquals(DiskBasedCache.readInt(bais), -20050711); assertEquals(DiskBasedCache.readInt(bais), Integer.MIN_VALUE); assertEquals(DiskBasedCache.readInt(bais), Integer.MAX_VALUE); }
@Test public void serializeInt() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DiskBasedCache.writeInt(baos, 0); DiskBasedCache.writeInt(baos, 19791214); DiskBasedCache.writeInt(baos, -20050711); DiskBasedCache.writeInt(baos, Integer.MIN_VALUE); DiskBasedCache.writeInt(baos, Integer.MAX_VALUE); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); assertEquals(DiskBasedCache.readInt(bais), 0); assertEquals(DiskBasedCache.readInt(bais), 19791214); assertEquals(DiskBasedCache.readInt(bais), -20050711); assertEquals(DiskBasedCache.readInt(bais), Integer.MIN_VALUE); assertEquals(DiskBasedCache.readInt(bais), Integer.MAX_VALUE); }