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

📄 installer.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                        state.previousCA);                }                                    state.permissions = Permissions.forDomain(classSecurityToken,                                                          securityDomain);                /*                 * To keep public key management simple, there is only one                 * trusted keystore. So it is possible that the CA for                 * the suite is untrusted. This may be done on purpose for                 * testing. This is OK, but do not confuse the user by saying                 * the untrusted suite is authorized, so set the CA name to                 * null.                 */                state.ca = null;            } else {                /*                 * For trusted suites, make sure an properties duplicated in                 * both the manifest and JAD are the same.                 */                if (state.jadUrl != null) {                    checkForJadManifestMismatches();                }                state.trusted = true;                state.permissions = getInitialPermissions(securityDomain);            }            if (state.isPreviousVersion) {                applyCurrentUserLevelPermissions(                  state.previousSuite.getPermissions()[Permissions.CUR_LEVELS],                    state.permissions[Permissions.MAX_LEVELS],                    state.permissions[Permissions.CUR_LEVELS]);                if (state.removeRMS) {                    // override suite comparisons, just remove RMS                    RecordStoreFile.removeRecordStoresForSuite(                        classSecurityToken,                        state.storageRoot + state.storageName);                } else {                    processPreviousRMS();                }            }            state.securityToken = new SecurityToken(classSecurityToken,                                                    state.permissions);            checkConfiguration();            matchProfile();            suiteStorageRoot = state.storageRoot + state.storageName;            // make sure at least 1 second has passed            while (System.currentTimeMillis() - state.startTime < 1000);            synchronized (state) {                // this is the point of no return, one last check                if (state.stopInstallation) {                    postInstallMsgBackToProvider(USER_CANCELLED_MSG);                    throw new IOException("stopped");                }                if (state.listener != null) {                    state.listener.updateStatus(STORING_SUITE, state);                }                state.writingSuite = true;            }            registerPushConnections();        } catch (Exception e) {            state.file.delete(state.tempFilename);            if (e instanceof IOException) {                throw (IOException)e;            }            throw (RuntimeException)e;        }        try {            state.file.rename(state.tempFilename,                              suiteStorageRoot + JAR_FILENAME);                        state.storage.connect(suiteStorageRoot + MANIFEST_FILENAME,                              RandomAccessStream.READ_WRITE_TRUNCATE);            state.storage.writeBytes(state.manifest, 0, state.manifest.length);            state.storage.disconnect();            if (state.file.exists(suiteStorageRoot + JAD_URL_FILENAME)) {                // erase the old JAD URL since we did not get new one                state.file.delete(suiteStorageRoot + JAD_URL_FILENAME);                state.file.delete(suiteStorageRoot + JAD_FILENAME);            }            if (state.jadUrl != null) {                // Save JAD, JAR & manifest files                state.storage.connect(suiteStorageRoot + JAD_FILENAME,                                   RandomAccessStream.READ_WRITE_TRUNCATE);                state.storage.writeBytes(state.jad, 0, state.jad.length);                state.storage.disconnect();                // convert the JAD URL to UTF8 and write it to storage                state.storage.connect(suiteStorageRoot + JAD_URL_FILENAME,                                  RandomAccessStream.READ_WRITE_TRUNCATE);                storageStream = state.storage.openDataOutputStream();                storageStream.writeUTF(state.jadUrl);                storageStream.close();                state.storage.disconnect();            }            // convert the JAR URL to UTF8 and write it to storage            state.storage.connect(suiteStorageRoot + JAR_URL_FILENAME,                                  RandomAccessStream.READ_WRITE_TRUNCATE);            storageStream = state.storage.openDataOutputStream();            storageStream.writeUTF(state.jarUrl);            storageStream.close();            state.storage.disconnect();            if (state.jadEncoding != null) {                // convert the JAD encoding to UTF8 and write it to storage                state.storage.connect(suiteStorageRoot + JAD_ENCODING_FILENAME,                                  RandomAccessStream.READ_WRITE_TRUNCATE);                storageStream = state.storage.openDataOutputStream();                storageStream.writeUTF(state.jadEncoding);                storageStream.close();                state.storage.disconnect();            } else if (state.file.exists(suiteStorageRoot +                                         JAD_ENCODING_FILENAME)) {                // erase the old encoding since we did not get new one                state.file.delete(suiteStorageRoot + JAD_ENCODING_FILENAME);            }            // todo get the jad encoding and write to a file            if (state.ca != null) {                // convert the domain owner to UTF8 and write it to storage                state.storage.connect(suiteStorageRoot + CA_FILENAME,                                  RandomAccessStream.READ_WRITE_TRUNCATE);                storageStream = state.storage.openDataOutputStream();                storageStream.writeUTF(state.ca);                storageStream.close();                state.storage.disconnect();            }            saveSuiteSettings(classSecurityToken, suiteStorageRoot,                state.pushInterruptSetting, state.permissions, state.trusted);            addToSuiteList(state.storageName);            state.nextStep++;            try {                postInstallMsgBackToProvider(SUCCESS_MSG);            } catch (RuntimeException re) {                /*                 * The suite is successfully installed, but the post of the                 * status message failed. Do not let this failure prevent                  * the suite from being used.                 */            }            return;        } catch (Exception e) {            try {                state.storage.disconnect();            } catch (IOException ex) {                // ignore            }            cleanUp(state.storageName);            if (e instanceof IOException) {                throw (IOException)e;            }            throw (RuntimeException)e;        }    }    /**     * Downloads an application descriptor file from the given URL.     *     * @return a byte array representation of the file or null if not found     *     * @exception IOException is thrown if any error prevents the download     *   of the JAD     */    private byte[] downloadJAD() throws IOException {        String[] encoding = new String[1];        ByteArrayOutputStream bos = new ByteArrayOutputStream(MAX_DL_SIZE);        String[] acceptableTypes = {JAD_MT};        String[] extraFieldKeys = new String[3];        String[] extraFieldValues = new String[3];        String locale;        String prof = System.getProperty("microedition.profiles");        int space = prof.indexOf(' ');        if (space != -1) {            prof = prof.substring(0, space);        }        extraFieldKeys[0] = "User-Agent";        extraFieldValues[0] = "Profile/" + prof                             + " Configuration/" +                             System.getProperty("microedition.configuration");        extraFieldKeys[1] = "Accept-Charset";        extraFieldValues[1] = "UTF-8, " +                              System.getProperty("microedition.encoding");        /* locale can be null */        locale = System.getProperty("microedition.locale");        if (locale != null) {            extraFieldKeys[2] = "Accept-Language";            extraFieldValues[2] = locale;        }        state.beginTransferDataStatus = DOWNLOADING_JAD;        state.transferStatus = DOWNLOADED_1K_OF_JAD;        /*         * Do not send the list of acceptable types because some servers         * will send a 406 if the URL is to a JAR. It is better to         * reject the resource at the client after check the media-type so         * if the type is JAR a JAR only install can be performed.         */        downloadResource(state.jadUrl, extraFieldKeys, extraFieldValues,                         acceptableTypes, false, false, bos, encoding,                         InvalidJadException.INVALID_JAD_URL,                         InvalidJadException.JAD_SERVER_NOT_FOUND,                         InvalidJadException.JAD_NOT_FOUND,                         InvalidJadException.INVALID_JAD_TYPE);        state.jadEncoding = encoding[0];        return bos.toByteArray();    }    /**     * Downloads an application archive file from the given URL into the     * given file. Automatically handle re-trys.     *     * @param filename name of the file to write. This file resides     *          in the storage area of the given application     *     * @return size of the JAR     *     * @exception IOException is thrown if any error prevents the download     *   of the JAR     */    private int downloadJAR(String filename)            throws IOException {        HttpUrl parsedUrl;        String url;        String[] acceptableTypes = {JAR_MT_1, JAR_MT_2};        int jarSize;        RandomAccessStream jarOutputStream = null;        OutputStream outputStream = null;        parsedUrl = new HttpUrl(state.jarUrl);        if (parsedUrl.authority == null && state.jadUrl != null) {            // relative URL, add the JAD URL as the base            try {                parsedUrl.addBaseUrl(state.jadUrl);            } catch (IOException e) {                postInstallMsgBackToProvider(INVALID_JAD_MSG);                throw new InvalidJadException(                         InvalidJadException.INVALID_JAR_URL);            }            url = parsedUrl.toString();            // The JAR URL saved to storage MUST be absolute            state.jarUrl = url;        } else {            url = state.jarUrl;        }        jarOutputStream = new RandomAccessStream(classSecurityToken);        jarOutputStream.connect(filename,                                RandomAccessStream.READ_WRITE_TRUNCATE);        outputStream = jarOutputStream.openOutputStream();        try {            state.beginTransferDataStatus = DOWNLOADING_JAR;            state.transferStatus = DOWNLOADED_1K_OF_JAR;            jarSize = downloadResource(url, null, null,                         acceptableTypes, true, true, outputStream, null,                         InvalidJadException.INVALID_JAR_URL,                         InvalidJadException.JAR_SERVER_NOT_FOUND,                         InvalidJadException.JAR_NOT_FOUND,                         InvalidJadException.INVALID_JAR_TYPE);            return jarSize;        } catch (InvalidJadException ije) {            switch (ije.getReason()) {            case InvalidJadException.JAR_SERVER_NOT_FOUND:            case InvalidJadException.JAR_NOT_FOUND:                postInstallMsgBackToProvider(INVALID_JAD_MSG);                break;            case InvalidJadException.INVALID_JAR_TYPE:                postInstallMsgBackToProvider(INVALID_JAR_MSG);            }            throw ije;        } finally {            try {                jarOutputStream.disconnect();            } catch (Exception e) {                // ignore            }        }    }    /**     * Downloads an resource from the given URL into the output stream.     *     * @param url location of the resource to download     * @param extraFieldKeys keys to the extra fields to put in the request     * @param extraFieldValues values to the extra fields to put in the request     * @param acceptableTypes list of acceptable media types for this resource,     *                        there must be at least one     * @param sendAcceptableTypes if true the list of acceptable media types     *       for this resource will be sent in the request     * @param allowNoMediaType if true it is not consider an error if     *       the media type is not in the response     *       for this resource will be sent in the request     * @param output output stream to write the resource to     * @param encoding an array to receive the character encoding of resource,     *                 can be null     * @param invalidURLCode reason code to use when the URL is invalid     * @param serverNotFoundCode reason code to use when the server is not     *     found     * @param resourceNotFoundCode reason code to use when the resource is not     *     found on the server     * @param invalidMediaTypeCode reason code to use when the media type of     *     the resource is not valid     *     * @return size of the resource     *     * @exception IOException is thrown if any error prevents the download     *   of the resource     */    private int downloadResource(String url, String[] extraFieldKeys,            String[] extraFieldValues, String[] acceptableTypes,            boolean sendAcceptableTypes, boolean allowNoMediaType,            OutputStream output, String[] encoding, int invalidURLCode,            int serverNotFoundCode, int resourceNotFoundCode,

⌨️ 快捷键说明

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