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

📄 installer.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            cookie.append(path);        }        return cookie.toString();    }    /**     * Post a status message back to the provider's URL in JAD.     *     * @param message status message to post     */    private void postStatusBackToProvider(String message) {        String url;        HttpConnection transaction;        OutputStream out;        if (state.jadProps == null) {            return;        }        url = state.jadProps.getProperty(NOTIFY_PROP);        if (url == null) {            return;        }        try {            transaction = (HttpConnection)Connector.open(url, Connector.WRITE);            try {                transaction.setRequestMethod(HttpConnection.POST);                if (state.cookie != null) {                    transaction.setRequestProperty("Cookie",                        formatReturnCookie(state.cookie));                }                out = transaction.openOutputStream();                try {                    out.write(message.getBytes());                } finally {                    out.close();                }            } finally {                transaction.close();            }        } catch (IOException ioe) {            // ignore IOExceptions        } catch (IllegalArgumentException iae) {            // ignore IllegalArgumentExceptions        } catch (ClassCastException cce) {            // ignore ClassCastExceptions        }    }    /**     * Function that actually does the work of transfering file data.     * <p>     * If the amount of data to be read is larger than <code>maxDLSize</code>     * we will break the input into chunks no larger than     * <code>maxDLSize</code>. This prevents the VM from running out of     * memory when processing large files.     *     * @param in the input stream to read from.     * @param out the output stream to write to.     *     * @return number of bytes written to the output stream     *     * @exception IOException if any exceptions occur during transfer     * of data.     */    private int transferData(InputStream in, OutputStream out)            throws IOException {        byte[] buffer = new byte[MAX_DL_SIZE];        int bytesRead;        int totalBytesWritten = 0;        try {            for (; ; ) {                bytesRead = in.read(buffer);                if (bytesRead == -1) {                    return totalBytesWritten;                }                out.write(buffer, 0, bytesRead);                totalBytesWritten += bytesRead;            }        } catch (IOException ioe) {            if (state.stopInstallation) {                postStatusBackToProvider(USER_CANCELLED_MSG);                throw new IOException("stopped");            } else {                throw ioe;            }        }    }    /**     * Stops the installation. If installer is not installing then this     * method has no effect. This will cause the install method to     * throw an IOException if the install is not writting the suite     * to storage which is the point of no return.     *     * @return true if the install will stop, false if it is too late     */    public boolean stopInstalling() {        if (state == null) {            return false;        }        synchronized (state) {            if (state.writingSuite) {                return false;            }                    state.stopInstallation = true;            try {                httpInputStream.close();            } catch (Exception e) {                // ignore            }            try {                httpConnection.close();            } catch (Exception e) {                // ignore            }            return true;        }    }    /**     * Tell if the installation was stopped by another thread.     * @return true if the installation was stopped by another thread.     */    public boolean wasStopped() {        if (state == null) {            return false;        }        return state.stopInstallation;    }    /**     * Gets the security domain name for this MIDlet Suite from storage.     *     * @param storageName given to the suite by the installer when it was     *        downloaded.     * @return name of the security domain for the MIDlet Suite     */    protected String getSecurityDomainName(String storageName) {        // This is a method that is overridden by a secure installer.        return "untrusted";    }    /**     * Parses a JAD.     * @param jad raw bytes of the jad     * @param enc character encoding used     * @param jadProps Properties specified in .jad file     * @exception IOException if any error prevents the reading     *   of the JAD     * @exception InvalidJadException if the JAD is not valid     */    public void parseJad(InputStream jad, String enc,                         JadProperties jadProps)            throws IOException, InvalidJadException {        // This is a method that is overridden by a secure installer.        jadProps.load(jad, enc);    }    /**     * Verifies a JAD.     * @param jad raw bytes of the jad     * @param jadProps Properties specified in .jad file     *     * @return name of the authorizing domain owner or null if not signed     *     * @exception IOException if any error prevents the reading     *   of the JAD     * @exception InvalidJadException if the JAD is not valid     */    protected String verifyJad(byte[] jad, Properties jadProps)            throws IOException, InvalidJadException {        // This is a place holder for a secure installer.        return null;    }    /**     * Verifies a Jar.     *     * @param jadProps Properties specified in .jad file     * @param jarStorage System store for applications     * @param jarFilename name of the jar to read.     *     * @exception IOException if any error prevents the reading     *   of the JAR     * @exception InvalidJadException if the JAR is not valid     */    protected void verifyJar(Properties jadProps,                             RandomAccessStream jarStorage,                             String jarFilename)        // This is a place holder for a secure installer.        throws IOException, InvalidJadException {    }    /**     * Compares two version strings. The return values are very similar to     * that of strcmp() in 'C'. If the first version is less than the second     * version, a negative number will be returned. If the first version is     * greater than the second version, a positive number will be returned.     * If the two versions are equal, zero is returned.     * <p>     * Versions must be in the form <em>xxx.yyy.zzz</em>, where:     * <pre>     *     <em>xxx</em> is the major version     *     <em>yyy</em> is the minor version     *     <em>zzz</em> is the micro version     * </pre>     * It is acceptable to omit the micro and possibly the minor versions.     * If these are not included in the version string, the period immediately     * preceding the number must also be removed. So, the versions     * <em>xxx.yyy</em> or <em>xxx</em> are also valid.     * <p>     * Version numbers do not have to be three digits wide. However, you may     * pad versions with leading zeros if desired.     * <p>     * If a version number is omitted, its value is assumed to be zero. All     * tests will be based on this assumption.     * <p>     * For example:     * <pre>     *    1.04  >  1.     *    1.04  <  1.4.1     *    1.04  =  1.4.0     * </pre>     * <p>     *     * @param ver1 the first version to compare.     * @param ver2 the second versoin to compare.     *     * @return  1 if <code>ver1</code> is greater than <code>ver2</code>     *          0 if <code>ver1</code> is equal to <code>ver2</code>     *         -1 if <code>ver1</code> is less than <code>ver2</code>     *     * @exception NumberFormatException if either <code>ver1</code> or      * <code>ver2</code> contain characters that are not numbers or periods.     */    private int vercmp(String ver1, String ver2)            throws NumberFormatException {        String strVal1;        String strVal2;        int    intVal1;        int    intVal2;        int    idx1 = 0;        int    idx2 = 0;        int    newidx;        if ((ver1 == null) && (ver2 == null)) {            return 0;        }        if (ver1 == null) {            return -1;        }        if (ver2 == null) {            return 1;        }        for (int i = 0; i < 3; i++) {            strVal1 = "0"; // Default value            strVal2 = "0"; // Default value            if (idx1 >= 0) {                newidx = ver1.indexOf('.', idx1);                if (newidx < 0) {                    strVal1 = ver1.substring(idx1);                } else {                    strVal1 = ver1.substring(idx1, newidx);                    newidx++; // Idx of '.'; need to go to next char                }                idx1 = newidx;            }            if (idx2 >= 0) {                newidx = ver2.indexOf('.', idx2);                if (newidx < 0) {                    strVal2 = ver2.substring(idx2);                } else {                    strVal2 = ver2.substring(idx2, newidx);                    newidx++;                }                idx2 = newidx;            }            intVal1 = Integer.parseInt(strVal1); // May throw NFE            intVal2 = Integer.parseInt(strVal2); // May throw NFE            if (intVal1 > intVal2) {                return 1;            }            if (intVal1 < intVal2) {                return -1;            }        }        return 0;    }    /**     * Checks the format of a version string.     * <p>     * Versions must be in the form <em>xxx.yyy.zzz</em>, where:     * <pre>     *     <em>xxx</em> is the major version     *     <em>yyy</em> is the minor version     *     <em>zzz</em> is the micro version     * </pre>     * It is acceptable to omit the micro and possibly the minor versions.     * If these are not included in the version string, the period immediately     * preceding the number must also be removed. So, the versions     * <em>xxx.yyy</em> or <em>xxx</em> are also valid.     * <p>     * Version numbers do not have to be three digits wide. However, you may     * pad versions with leading zeros if desired.     *     * @param ver the version to check.     *     * @exception NumberFormatException if <code>ver</code>      *     contains any characters that are not numbers or periods.     */    private void checkVersionFormat(String ver) throws NumberFormatException {        int length;        int start = 0;        int end;        length = ver.length();        for (int i = 0; ; i++) {            // check for more than 3 parts or a trailing '.'            if (i == 3 || start == length) {                throw new NumberFormatException();            }            end = ver.indexOf('.', start);            if (end == -1) {                end = length;            }            // throws NFE if the substring is not all digits            Integer.parseInt(ver.substring(start, end));            if (end == length) {                // we are done                return;            }            // next time around start after the index of '.'            start = end + 1;        }    }    /**     * Gets the MIDlet Suite from storage.     *     * @param storageName given to the suite by the installer     *                   when it was downloaded.     * @return MIDlet Suite for use by the Scheduler     */    public MIDletSuite getMIDletSuite(String storageName) {        r

⌨️ 快捷键说明

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