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

📄 installer.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            int invalidMediaTypeCode) throws IOException {        Connection conn = null;        StringBuffer acceptField;        int responseCode;        String retryAfterField;        int retryInterval;        String mediaType;        try {            for (; ; ) {                try {                    conn = Connector.open(url, Connector.READ);                } catch (IllegalArgumentException e) {                    throw new InvalidJadException(invalidURLCode, url);                } catch (ConnectionNotFoundException e) {                    // protcol not found                    throw new InvalidJadException(invalidURLCode, url);                }                if (!(conn instanceof HttpConnection)) {                    // only HTTP or HTTPS are supported                    throw new InvalidJadException(invalidURLCode, url);                }                httpConnection = (HttpConnection)conn;                if (extraFieldKeys != null) {                     for (int i = 0; i < extraFieldKeys.length &&                            extraFieldKeys[i] != null; i++) {                        httpConnection.setRequestProperty(extraFieldKeys[i],                                                          extraFieldValues[i]);                    }                }                                    // 256 is given to avoid resizing without adding lengths                acceptField = new StringBuffer(256);                if (sendAcceptableTypes) {                    // there must be one or more acceptable media types                    acceptField.append(acceptableTypes[0]);                    for (int i = 1; i < acceptableTypes.length; i++) {                        acceptField.append(", ");                        acceptField.append(acceptableTypes[i]);                    }                    httpConnection.setRequestProperty("Accept",                                                      acceptField.toString());                }                httpConnection.setRequestMethod(HttpConnection.GET);                if (state.username != null &&                        state.password != null) {                    httpConnection.setRequestProperty("Authorization",                        formatAuthCredentials(state.username,                                              state.password));                }                if (state.proxyUsername != null &&                        state.proxyPassword != null) {                    httpConnection.setRequestProperty("Proxy-Authorization",                        formatAuthCredentials(state.proxyUsername,                                              state.proxyPassword));                }                try {                    responseCode = httpConnection.getResponseCode();                } catch (IOException ioe) {                    if (httpConnection.getHost() == null) {                        throw new InvalidJadException(invalidURLCode, url);                    }                    throw new InvalidJadException(serverNotFoundCode, url);                }                if (responseCode != HttpConnection.HTTP_UNAVAILABLE) {                    break;                }                retryAfterField = httpConnection.getHeaderField("Retry-After");                if (retryAfterField == null) {                    break;                }                try {                    /*                     * see if the retry interval is in seconds, and                     * not an absolute date                     */                    retryInterval = Integer.parseInt(retryAfterField);                    if (retryInterval > 0) {                        if (retryInterval > 60) {                            // only wait 1 min                            retryInterval = 60;                        }                        Thread.sleep(retryInterval * 1000);                    }                } catch (InterruptedException ie) {                    // ignore thread interrupt                    break;                } catch (NumberFormatException ne) {                    // ignore bad format                    break;                }                httpConnection.close();                if (state.stopInstallation) {                    postInstallMsgBackToProvider(USER_CANCELLED_MSG);                    throw new IOException("stopped");                }            } // end for            if (responseCode == HttpConnection.HTTP_NOT_FOUND) {                throw new InvalidJadException(resourceNotFoundCode);            }            if (responseCode == HttpConnection.HTTP_NOT_ACCEPTABLE) {                throw new InvalidJadException(invalidMediaTypeCode, "");            }            if (responseCode == HttpConnection.HTTP_UNAUTHORIZED) {                // automatically throws the correct exception                checkIfBasicAuthSupported(                     httpConnection.getHeaderField("WWW-Authenticate"));                state.exception =                     new InvalidJadException(InvalidJadException.UNAUTHORIZED);                return 0;            }            if (responseCode == HttpConnection.HTTP_PROXY_AUTH) {                // automatically throws the correct exception                checkIfBasicAuthSupported(                     httpConnection.getHeaderField("WWW-Authenticate"));                state.exception =                    new InvalidJadException(InvalidJadException.PROXY_AUTH);                return 0;            }            if (responseCode != HttpConnection.HTTP_OK) {                throw new IOException("Failed to download " + url +                    " HTTP response code: " + responseCode);            }            mediaType = getMediaType(httpConnection.getType());            if (mediaType != null) {                boolean goodType = false;                for (int i = 0; i < acceptableTypes.length; i++) {                    if (mediaType.equals(acceptableTypes[i])) {                        goodType = true;                        break;                    }                }                if (!goodType) {                    throw new InvalidJadException(invalidMediaTypeCode,                                                  mediaType);                }            } else if (!allowNoMediaType) {                throw new InvalidJadException(invalidMediaTypeCode, "");            }            if (encoding != null) {                encoding[0] = getCharset(httpConnection.getType());            }            httpInputStream = httpConnection.openInputStream();            return transferData(httpInputStream, output);        } finally {            // Close the streams or connections this method opened.            try {                httpInputStream.close();            } catch (Exception e) {                // ignore            }                                try {                conn.close();            } catch (Exception e) {                // ignore            }        }    }    /**     * If the JAD belongs to an installed suite, check the URL against the     * installed one. Set the state.exception if the user needs to be warned.     *     * @param url JAD or JAR URL of the suite being installed     */    private void checkForDifferentDomains(String url) {        // perform a domain check not a straight compare        if (state.ca == null && state.previousUrl != null) {            HttpUrl old = new HttpUrl(state.previousUrl);            HttpUrl current = new HttpUrl(url);            if ((current.domain != null && old.domain == null) ||                (current.domain == null && old.domain != null) ||                (current.domain != null && old.domain != null &&                 !current.domain.regionMatches(true, 0, old.domain, 0,                                           old.domain.length()))) {                /*                 * The jad is at new location, could be bad,                 * let the user decide                 */                state.exception = new InvalidJadException(                                      InvalidJadException.JAD_MOVED,                                      (state.previousUrl == null ? "none" :                                      state.previousUrl));                return;            }        }    }    /**     * See if there is an installed version of the suite being installed and     * if so, make an necessary checks. Will set state fields, including     * the exception field for warning the user.     *     * @exception InvalidJadException if the new version is formated     * incorrectly     */    private void checkPreviousVersion() throws InvalidJadException {        MIDletSuite midletSuite;        String installedVersion;        int cmpResult;                // Check if app already exists        midletSuite = getMIDletSuite(state.storageName);        try {            checkVersionFormat(state.version);            if (midletSuite == null) {                // there is no previous version                return;            }            state.isPreviousVersion = true;            state.previousSuite = midletSuite;            // get this now so we do not have to save the whole suite object            state.previousJadUrl = midletSuite.getJadUrl();            state.previousJarUrl = midletSuite.getJarUrl();            state.previousUrl = midletSuite.getDownloadUrl();            state.previousCA = midletSuite.getCA();            if (state.previousCA == null) {                state.previousCA = Resource.getString("the manufacturer");            }            if (state.force) {                // do not ask questions, force an overwrite                return;            }            // If it does, check version information            installedVersion = midletSuite.getProperty(VERSION_PROP);            cmpResult = vercmp(state.version, installedVersion);            if (cmpResult < 0) {                // older version, warn user                state.exception = new InvalidJadException(                                  InvalidJadException.OLD_VERSION,                                  installedVersion);                return;            }            if (cmpResult == 0) {                // already installed, warn user                state.exception = new InvalidJadException(                                  InvalidJadException.ALREADY_INSTALLED,                                  installedVersion);                return;            }            // new version, warn user            state.exception = new InvalidJadException(                                  InvalidJadException.NEW_VERSION,                                  installedVersion);            return;        } catch (NumberFormatException nfe) {            postInstallMsgBackToProvider(INVALID_JAD_MSG);            throw new                InvalidJadException(InvalidJadException.INVALID_VERSION);        }    }    /**     * If this is an update, make sure the RMS data is handle correctly     * according to the OTA spec.     * <p>     * From the OTA spec:     * <blockquote>     * The RMS record stores of a MIDlet suite being updated MUST be     * managed as follows:</p>     * <ul>     * <li>     *   If the cryptographic signer of the new MIDlet suite and the     *   original MIDlet suite are identical, then the RMS record     *   stores MUST be retained and made available to the new MIDlet     *   suite.</li>     * <li>     *   If the scheme, host, and path of the URL that the new     *   Application Descriptor is downloaded from is identical to the     *   scheme, host, and path of the URL the original Application     *   Descriptor was downloaded from, then the RMS MUST be retained     *   and made available to the new MIDlet suite.</li>     * <li>     *   If the scheme, host, and path of the URL that the new MIDlet     *   suite is downloaded from is identical to the scheme, host, and     *   path of the URL the original MIDlet suite was downloaded from,     *   then the RMS MUST be retained and made available to the new     *   MIDlet suite.</li>     * <li>     *   If the above statements are false, then the device MUST ask     *   the user whether the data from the original MIDlet suite     *   should be retained and made available to the new MIDlet     *   suite.</li>     * </ul>     * </blockquote>     *     * @exception IOException if the install is stopped     */    private void processPreviousRMS() throws IOException {        HttpUrl newUrl;        HttpUrl originalUrl;        String suiteStorageRoot = state.storageRoot + state.storageName;        if (!RecordStoreFile.suiteHasRmsData(suiteStorageRoot)) {            return;        }        if (state.previousCA != null && state.ca != null &&                state.ca.equals(state.previousCA)) {            // signers the same            return;        }        try {            newUrl = new HttpUrl(state.jadUrl);            originalUrl = new HttpUrl(state.previousJadUrl);            if (newUrl.scheme.equals(originalUrl.scheme) &&                    newUrl.host.equals(originalUrl.host) &&        

⌨️ 快捷键说明

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