⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jumpinstallertool.java

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                    System.out.println("");                }                content = installers[i].getInstalled();            }        }    }            /**     *  Install JUMP content     *  url - URL of content to install, must be a file protocol URL     *  desc - download descriptor object     */    private JUMPContent[] install(URL url[], JUMPDownloadDescriptor desc[]) {        Vector contentVector = new Vector();                if (url.length != desc.length) {            System.err.println("ERROR: Number of URLs to install does not equal the number of given download descriptors.");            error();            return null;        }        for (int i = 0; i < url.length; i++) {            if (desc != null && url != null) {                if (!url[i].getProtocol().equals("file")) {                    System.out.println("ERROR: Invalid protocol for:" + url[i].toString());                    continue;                }                System.out.println("");                System.out.println("==> Installing: " + desc[i].getName() + " from: " + url[i].toString());                Properties apps[] = desc[i].getApplications();                if (apps == null) {                    trace("ERROR: Could not install. Descriptor contains no information on application.");                    error();                    return null;                }                String appType = apps[0].getProperty("JUMPApplication_appModel");                JUMPInstallerModule installer = null;                if (appType.equals("xlet")) {                    installer = createInstaller(JUMPAppModel.XLET);                } else if (appType.equals("main")) {                    installer = createInstaller(JUMPAppModel.MAIN);                } else if (appType.equals("midlet")) {                    installer = createInstaller(JUMPAppModel.MIDLET);                } else {                    trace("ERROR: Unknown application type: " + appType);                    error();                    return null;                }                JUMPContent installedApps[] = installer.install(url[i], desc[i]);                if (installedApps != null) {                    // Print installed apps.                    for(int j = 0; j < installedApps.length; j++) {                        System.out.println("Application Installed: " + ((JUMPApplication)installedApps[j]).getTitle());                        contentVector.add(installedApps[j]);                    }                } else {                    System.out.println("ERROR: No applications were installed for: " + desc[i].getName() + ".");                    error();                }                System.out.println("==> Finished Installing: " + desc[i].getName());                System.out.println("");            }        }                return (JUMPContent[])contentVector.toArray(new JUMPContent[]{});    }        /**     * Print out a list of all installed content.     */    public void doList() {        System.out.println("");        System.out.println("---------------------------------");        System.out.println("Applications Within Content Store");        System.out.println("---------------------------------");        System.out.println("");                JUMPInstallerModule installers[] = JUMPInstallerModuleFactory.getInstance().getAllInstallers();                int numApps = 0;                for (int i = 0; i < installers.length; i++) {                        JUMPContent[] content = installers[i].getInstalled();            if (content != null) {                for(int j = 0; j < content.length; j++) {                    numApps++;                    System.out.println("App #" + numApps + ": " + ((JUMPApplication)content[j]).getTitle());                }            }        }                System.out.println("");    }        class DownloadTool {                private String provisioningServerURL = null;                // Values only used for a JSR 124 server        private final String omaSubDirectory = "oma";        private final String midpSubDirectory = "jam";                private boolean downloadFinished = false;        private boolean downloadAborted = false;                String outputFile = null;                byte[] buffer = null;        int bufferIndex = 0;                private Vector descriptorVector = null;        private Vector urlVector = null;                        private String downloadNames[] = null;        private String downloadURIs[] = null;                public DownloadTool() {            setup();        }                public DownloadTool(String provisioningServerURL) {            this.provisioningServerURL = provisioningServerURL;            setup();        }                void setup() {            descriptorVector = new Vector();            urlVector = new Vector();        }                public URL[] getURLs() {            return (URL[])urlVector.toArray(new URL[]{});        }                public JUMPDownloadDescriptor[] getDescriptors() {            return (JUMPDownloadDescriptor[])descriptorVector.toArray(new JUMPDownloadDescriptor[]{});        }                public void startTool(String downloadName, String downloadURI) {            String tmpDownloadNames[] = new String[1];            String tmpDownloadURIs[] = new String[1];            tmpDownloadNames[0] = downloadName;            tmpDownloadURIs[0] = downloadURI;            startTool(tmpDownloadNames, tmpDownloadURIs);        }                public void startTool(String downloadNames[], String downloadURIs[]) {            this.downloadNames = downloadNames;            this.downloadURIs = downloadURIs;            nonInteractiveDownload(downloadURIs, downloadNames);        }                public void startTool(boolean userInteractive) {            // Determine the discovery URL            if (provisioningServerURL != null) {                System.out.println( "Using provisioning server URL at: " + provisioningServerURL );            } else {                System.out.println("A provisioning server url needs to be supplied.");                System.out.println("Please run again with an value set to the -ProvisioningServerURL flag.");                System.exit(0);            }                        // Check if we're using a JSR 124 server            if (provisioningServerURL.endsWith("ri-test")) {                                HashMap applistOMA = new OTADiscovery().discover(provisioningServerURL + "/" + omaSubDirectory);                HashMap applistMIDP = new OTADiscovery().discover(provisioningServerURL + "/" + midpSubDirectory);                                downloadURIs = new String[ applistOMA.size() + applistMIDP.size() ];                downloadNames = new String[ applistOMA.size() + applistMIDP.size() ];                                int i = 0;                for ( Iterator e = applistOMA.keySet().iterator(); e.hasNext(); ) {                    String s = (String)e.next();                    downloadURIs[ i ] = s;                    downloadNames[ i ] = (String)applistOMA.get( s );                    i++;                }                                for ( Iterator e = applistMIDP.keySet().iterator(); e.hasNext(); ) {                    String s = (String)e.next();                    downloadURIs[ i ] = s;                    downloadNames[ i ] = (String)applistMIDP.get( s );                    i++;                }            } else {                // we're using an apache-based server                HashMap applist = new OTADiscovery().discover(provisioningServerURL);                                downloadURIs = new String[ applist.size() ];                downloadNames = new String[ applist.size() ];                                int i = 0;                for ( Iterator e = applist.keySet().iterator(); e.hasNext(); ) {                    String s = (String)e.next();                    downloadURIs[ i ] = s;                    downloadNames[ i ] = (String)applist.get( s );                    i++;                }            }                        if (userInteractive) {                userInteractiveDownload(downloadURIs, downloadNames);            } else {                nonInteractiveDownload(downloadURIs, downloadNames);            }                    }                void nonInteractiveDownload(String[] downloadURIs, String[] downloadNames) {            for (int i = 0; i < downloadURIs.length; i++) {                trace("Downloading: " + downloadNames[i]);                doDownload(downloadNames[i], downloadURIs[i]);            }        }                void userInteractiveDownload(String[] downloadURIs, String[] downloadNames) {                        // Show what is available and read input for a choice.            System.out.println( "download choices: " );            for (int i = 0; i < downloadNames.length ; i++ ) {                System.out.println( "(" + i + "): " + downloadNames[ i ] );            }            String message = "Enter choice (-1 to exit) [-1]: ";            String choice = Utilities.promptUser(message);            System.out.println("--> choice: " + choice);            int chosenDownload = Integer.parseInt(choice);            System.out.println("--> chosenDownload: " + chosenDownload);            // If no valid choice, quit            if ( chosenDownload < 0 ) {                System.exit( 0 );            }                        System.out.println( chosenDownload + ": " + downloadURIs[ chosenDownload ] );            boolean rv = doDownload(downloadNames[chosenDownload], downloadURIs[chosenDownload]);        }                private boolean doDownload(String name, String uri) {            // Initiate a download. We've specified ourselves            // as the handler of the data.            if (uri.endsWith(".dd")) {                startDownload(name, uri, JUMPDownloadModuleFactory.PROTOCOL_OMA_OTA);            } else if (uri.endsWith(".jad")) {                startDownload(name, uri, JUMPDownloadModuleFactory.PROTOCOL_MIDP_OTA);            } else {                System.out.println("ERROR: Unknown URI type: " + uri);                System.exit(0);            }                        // Wait for either failure or success            while ( downloadFinished == false &&                    downloadAborted == false ) {                System.out.println( "waiting for download" );                try {                    Thread.sleep( 100 );                } catch ( java.lang.InterruptedException ie ) {                    ie.printStackTrace();                    // Eat it                }            }                        // Some resolution            if ( ! downloadFinished ) {                trace( "Download failed!" );                return false;            } else {                trace( "Download succeeded!" );                return true;            }        }                void startDownload(String name, String uri, String protocol) {            downloadFinished = false;            downloadAborted = false;                        System.out.println("");            System.out.println("==> Downloading: " + name);                        trace( "Creating descriptor for " + uri );                        JUMPDownloadModule module =                    JUMPDownloadModuleFactory.getInstance().getModule(protocol);                        try {                                JUMPDownloadDescriptor descriptor = module.createDescriptor( uri );                if (descriptor == null) {                    System.out.println("ERROR: Returned descriptor is NULL for " + uri);                    System.exit(0);                }                                JUMPDownloader downloader = module.createDownloader(descriptor);                JUMPDownloadDestination destination = new DownloadDestinationImpl(descriptor);                                // Trigger the download                URL url = downloader.start( destination );                trace( "Download returns url: " + url);                                downloadFinished = true;                                descriptorVector.add(descriptor);                urlVector.add(url);            } catch ( JUMPDownloadException o ) {                System.out.println( "Download failed for " + uri);                if (Verbose) {                    o.printStackTrace();                }                downloadAborted = true;            } catch ( Exception o ) {                System.out.println( "Download failed for " + uri);                if (Verbose) {                    o.printStackTrace();                }                downloadAborted = true;            } finally {                System.out.println("==> Finished Downloading: " + name);                System.out.println("");            }        }    }        /**     * The main method when used as a standalone tool.     * @param args program args.  See docs for details.     */    public static void main(String[] args) {        new JUMPInstallerTool(args);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -