package com.marinilli.b2.c11;
import com.marinilli.b2.c11.util.*;
import javax.jnlp.*;
import java.net.URL;
import java.io.*;
/**
 * Chapter 11 - Example of DownloadService
 * @author Mauro Marinilli
 * @version 1.0
 */
public class DownloadExample {
  public DownloadExample() {
    removeFromJNLPCache("anapp.jar");
  }
  public static void removeFromJNLPCache(String resourceName){
    DownloadService ds = null;
    ds = (DownloadService)Utilities.getService("javax.jnlp.DownloadService");
    URL url = null;
    try {
      url = new URL(Utilities.getBasicService().getCodeBase(), resourceName);
    } catch(IOException exc) {
      System.out.println("Creating URL: "+exc);
    }
    try {
      ds.removeResource(url ,null);
      System.out.println("Resource "+url+" removed from JNLP cache.");
    } catch(IOException exc) {
      System.out.println("removing resource from JNLP cache: "+exc);
    }
  }
}