Search in sources :

Example 1 with FileContents

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;
}
Also used : PersistenceService(javax.jnlp.PersistenceService) MalformedURLException(java.net.MalformedURLException) FileContents(javax.jnlp.FileContents) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) UnavailableServiceException(javax.jnlp.UnavailableServiceException) NamingException(javax.naming.NamingException) MalformedURLException(java.net.MalformedURLException) UnavailableServiceException(javax.jnlp.UnavailableServiceException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with FileContents

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?!";
        }
    }
}
Also used : Serializable(java.io.Serializable) FileContents(javax.jnlp.FileContents) BufferedInputStream(java.io.BufferedInputStream) XMLDecoder(java.beans.XMLDecoder) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with FileContents

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();
}
Also used : Cartridge(org.javatari.atari.cartridge.Cartridge) FileContents(javax.jnlp.FileContents) AccessControlException(java.security.AccessControlException) File(java.io.File)

Example 4 with FileContents

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;
    }
}
Also used : FileContents(javax.jnlp.FileContents) FileOpenService(javax.jnlp.FileOpenService)

Example 5 with FileContents

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);
    }
}
Also used : XMLEncoder(java.beans.XMLEncoder) Serializable(java.io.Serializable) FileContents(javax.jnlp.FileContents) HashMap(java.util.HashMap) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

FileContents (javax.jnlp.FileContents)5 IOException (java.io.IOException)3 Serializable (java.io.Serializable)2 UncheckedIOException (java.io.UncheckedIOException)2 HashMap (java.util.HashMap)2 XMLDecoder (java.beans.XMLDecoder)1 XMLEncoder (java.beans.XMLEncoder)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 AccessControlException (java.security.AccessControlException)1 Map (java.util.Map)1 Properties (java.util.Properties)1 FileOpenService (javax.jnlp.FileOpenService)1 PersistenceService (javax.jnlp.PersistenceService)1 UnavailableServiceException (javax.jnlp.UnavailableServiceException)1