javax.jnlp.PersistenceService Java Examples

The following examples show how to use javax.jnlp.PersistenceService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebstartPersistence.java    From marauroa with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a instance of class
 */
public WebstartPersistence() {
	try {
		ps = (PersistenceService) ServiceManager.lookup("javax.jnlp.PersistenceService");
		bs = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService");

		if (ps != null && bs != null) {
			codebase = bs.getCodeBase();
		}

	} catch (UnavailableServiceException e) {
		e.printStackTrace(System.err);
		ps = null;
		bs = null;
	}
}
 
Example #2
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
protected static void saveWindowState(PersistenceService ps, URL codebase, WindowState windowState) {
  try {
    FileContents fc = ps.get(codebase);
    try (XMLEncoder e = new XMLEncoder(new BufferedOutputStream(fc.getOutputStream(true)))) {
      // Test: delete muf ex. C:\Users\(user)\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\muffin\xxxxxx-xxxxx.muf
      // ps.delete(codebase);
      // ObjectOutputStream e = new ObjectOutputStream(fc.getOutputStream(true));
      HashMap<String, Serializable> map = new HashMap<>();
      map.put("size", (Serializable) windowState.getSize());
      map.put("location", (Serializable) windowState.getLocation());
      // Test1: map.put("setting", (Serializable) windowState);
      // Test2: e.writeObject(windowState);
      e.writeObject(map);
      e.flush();
      // e.close();
    }
  } catch (IOException ex) {
    throw new UncheckedIOException(ex);
  }
}
 
Example #3
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private static void loadWindowState(PersistenceService ps, URL codebase, WindowState windowState) {
  try {
    FileContents fc = ps.get(codebase);
    try (XMLDecoder d = new XMLDecoder(new BufferedInputStream(fc.getInputStream()))) {
      @SuppressWarnings("unchecked") Map<String, Serializable> map = (Map<String, Serializable>) d.readObject();
      // d.close();
      windowState.setSize((Dimension) map.get("size"));
      windowState.setLocation((Point) map.get("location"));
      // // Test:
      // // ObjectInputStream d = new ObjectInputStream(appSettings.getInputStream());
      // // WindowState cache = (WindowState) d.readObject();
      // // Test:
      // WindowState cache = (WindowState) map.get("setting");
      // System.out.println("aaa: " + cache.getSize());
      // System.out.println("aaa: " + cache.getLocation());
    }
  } catch (IOException ex) {
    // create the cache
    try {
      long size = ps.create(codebase, 64_000);
      System.out.println("Cache created - size: " + size);
    } catch (IOException ioex) {
      // PMD: PreserveStackTrace false positive when using UncheckedIOException in the nested try-catch blocks?
      // throw new UncheckedIOException("Application codebase is not a valid URL?!", ioex);
      assert false : "Application codebase is not a valid URL?!";
    }
  }
}