views:

20

answers:

1

My Java Webstart application download some large resource files. I use:

URL url = new URL( "http://....." );
URLConnection uc = url.openConnection();
uc.setUseCaches( true );
uc.getInputStream();

But on the next start the resources are downloaded again. The files occur also not in the resources list of the temporary Internet files.

In older Java versions this has work. Any idea how I can use this cache with the current version?

A: 

Not with older Java version it has work. It has work with Java Applets. Here is a solution how you can enable the Java Cache also for JNLP. You need to call once JnlpResponseCache.init() in your code to enable it.

class JnlpResponseCache extends ResponseCache {
    private final DownloadService service;

    private JnlpResponseCache(){
        try {
            service = (DownloadService)ServiceManager.lookup("javax.jnlp.DownloadService");
        } catch( UnavailableServiceException ex ) {
            throw new NoClassDefFoundError( ex.toString() );
        } 
    }

    static void init(){
        if( ResponseCache.getDefault() == null ){
            ResponseCache.setDefault( new JnlpResponseCache() );
        }
    }

    @Override
    public CacheResponse get( URI uri, String rqstMethod, Map<String, List<String>> rqstHeaders ) throws IOException {
        return null;
    }

    @Override
    public CacheRequest put( URI uri, URLConnection conn ) throws IOException {
        URL url = uri.toURL();
        service.loadResource( url, null, service.getDefaultProgressWindow() );
        return null;
    }

}
Horcrux7