import java.io.*;
import java.net.*;
import java.util.*;
public class WebCache {
WeakHashMap cache = new WeakHashMap();
public class WebObject {
public String type;
public byte[] content;
}
public WebObject get( String spec )
throws MalformedURLException,IOException {
URL url = new URL(spec);
WebObjectobj = (WebObject)cache.get(url);
if ( obj == null ) {
URLConnectionconn = url.openConnection();
obj = new WebObject();
obj.type = conn.getContentType();
obj.content = new byte[conn.getContentLength()];
conn.getInputStream().read( obj.content );
cache.put( url, obj );
}
return obj;
}
}