use of javax.jnlp.FileContents in project adempiere by adempiere.
the class Ini method loadWebStartProperties.
// loadProperties
private static boolean loadWebStartProperties() {
boolean loadOK = true;
boolean firstTime = false;
s_prop = new Properties();
PersistenceService ps;
try {
ps = (PersistenceService) ServiceManager.lookup("javax.jnlp.PersistenceService");
} catch (UnavailableServiceException e) {
ps = null;
log.log(Level.SEVERE, e.toString());
return false;
}
FileContents fc = null;
try {
fc = ps.get(getCodeBase());
} catch (MalformedURLException e) {
log.log(Level.SEVERE, e.toString());
return false;
} catch (FileNotFoundException e) {
try {
ps.create(getCodeBase(), 16 * 1024);
ps.setTag(getCodeBase(), PersistenceService.DIRTY);
fc = ps.get(getCodeBase());
} catch (Exception e1) {
}
} catch (IOException e) {
log.log(Level.SEVERE, e.toString());
return false;
}
try {
InputStream is = fc.getInputStream();
s_prop.load(is);
is.close();
} catch (Throwable t) {
log.log(Level.SEVERE, t.toString());
loadOK = false;
}
if (!loadOK || s_prop.getProperty(P_TODAY, "").equals("")) {
firstTime = true;
if (isShowLicenseDialog())
if (!IniDialog.accept())
System.exit(-1);
checkProperties();
}
// Save if not exist or could not be read
if (!loadOK || firstTime)
saveWebStartProperties();
s_loaded = true;
s_propertyFileName = getCodeBase().toString();
return firstTime;
}
use of javax.jnlp.FileContents in project java-swing-tips by aterai.
the class LoadSaveTask method loadWindowState.
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 ignore) {
// throw new UncheckedIOException("Application codebase is not a valid URL?!", ignore);
assert false : "Application codebase is not a valid URL?!";
}
}
}
use of javax.jnlp.FileContents in project javatari by ppeccin.
the class Monitor method loadCartridgeFromFile.
private void loadCartridgeFromFile(boolean autoPower) {
if (cartridgeChangeDisabledWarning())
return;
display.displayLeaveFullscreen();
Cartridge cart = null;
try {
File file = FileROMChooser.chooseFileToLoad();
if (file != null)
cart = ROMLoader.load(file);
} catch (AccessControlException e) {
// Automatically tries FileServiceChooser if access is denied
FileContents fileContents = FileServiceROMChooser.chooseFileToLoad();
if (fileContents != null)
cart = ROMLoader.load(fileContents);
}
if (cart != null)
cartridgeInsert(cart, autoPower);
else
display.displayRequestFocus();
}
use of javax.jnlp.FileContents in project javatari by ppeccin.
the class FileServiceROMChooser method chooseFileToLoad.
public static FileContents chooseFileToLoad() {
try {
FileOpenService fos = (FileOpenService) ServiceManager.lookup("javax.jnlp.FileOpenService");
FileContents fileCon = fos.openFileDialog(null, ROMLoader.VALID_LOAD_FILE_EXTENSIONS);
if (fileCon == null)
return null;
return fileCon;
} catch (Exception ex) {
System.out.println("File Service Cartridge Chooser: unable to open dialog\n" + ex);
return null;
}
}
use of javax.jnlp.FileContents in project java-swing-tips by aterai.
the class LoadSaveTask method saveWindowState.
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\xxx-xxx.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);
}
}
Aggregations