Package com.sun.midp.io.j2me.storage

Examples of com.sun.midp.io.j2me.storage.RandomAccessStream


        Vector CSRs = new Vector();

      String storeName = File.getStorageRoot(
      Constants.INTERNAL_STORAGE_ID) + CSR_ID_FILE;
      RandomAccessStream storage =
                new RandomAccessStream(classSecurityToken);
        DataInputStream dis;

        try {
            storage.connect(storeName, Connector.READ);
            dis = new DataInputStream(storage.openInputStream());
        } catch (IOException ioe) {

            try {
                storage.connect(storeName, Connector.READ_WRITE);
                DataOutputStream dos = storage.openDataOutputStream();
                dos.writeInt(0);
                dos.flush();
                dos.close();
                dis = new DataInputStream(storage.openInputStream());
            } catch (IOException openwe) {
                return CSRs;
            }
            try {
                storage.disconnect();
            } catch (IOException e) {} // ignored
            return CSRs;
        }

        try {
            int count = dis.readInt();
            while (count-- > 0) {
                byte[] id = new byte[20];
                dis.read(id, 0, 20);
                CSRs.addElement(id);
            }
        } catch (IOException e) {} // ignored
        finally {
            try {
                storage.disconnect();
            } catch (IOException e) {} // ignored
        }
        return CSRs;
    }
View Full Code Here


            return;
        }

        String storeName = File.getStorageRoot(
      Constants.INTERNAL_STORAGE_ID) + CSR_ID_FILE;
        RandomAccessStream storage =
                new RandomAccessStream(classSecurityToken);
        DataOutputStream dos;

        try {
            storage.connect(storeName, Connector.WRITE);
            dos = storage.openDataOutputStream();
            int len = CSRs.size();
            dos.writeInt(len);
            for (int i = 0; i < len; i++) {
                dos.write((byte[]) CSRs.elementAt(i));
            }
            dos.flush();
            dos.close();
            storage.truncate(4 + len * 20);
        } catch (IOException openwe) {} // ignored
        finally {
            try {
                storage.disconnect();
            } catch (IOException e) {} // ignored
        }
    }
View Full Code Here

        if (state.exception != null) {
            return;
        }

        try {
            state.storage = new RandomAccessStream();

            state.installInfo.authPath =
                verifier.verifyJar(state.storage, info.jarFilename);

            if (state.listener != null) {
View Full Code Here

     *
     * @exception IOException is thrown if any error prevents the download
     *            of the JAD
     */
    protected byte[] downloadJAD() throws IOException {
        RandomAccessStream jadInputStream;
        ByteArrayOutputStream bos = new ByteArrayOutputStream(CHUNK_SIZE);
        String jadFilename = getUrlPath(state.localJadUrl);

        state.beginTransferDataStatus = DOWNLOADING_JAD;
        state.transferStatus = DOWNLOADED_1K_OF_JAD;

        jadInputStream = new RandomAccessStream();
        jadInputStream.connect(jadFilename, Connector.READ);

        transferData(jadInputStream.openInputStream(), bos, CHUNK_SIZE);

        jadInputStream.close();

        return bos.toByteArray();
    }
View Full Code Here

     * @exception IOException is thrown if any error prevents the download
     *   of the JAR
     */
    protected int downloadJAR(String filename) throws IOException {
        int jarSize;
        RandomAccessStream jarInputStream, jarOutputStream;
        String jarFilename = getUrlPath(state.localJarUrl);

        // Open source (jar) file
        jarInputStream = new RandomAccessStream();
        jarInputStream.connect(jarFilename, Connector.READ);

        // Open destination (temporary) file
        jarOutputStream = new RandomAccessStream();
        jarOutputStream.connect(filename,
                                RandomAccessStream.READ_WRITE_TRUNCATE);

        // transfer data
        state.beginTransferDataStatus = DOWNLOADING_JAR;
        state.transferStatus = DOWNLOADED_1K_OF_JAR;

        jarSize = transferData(jarInputStream.openInputStream(),
                               jarOutputStream.openOutputStream(), CHUNK_SIZE);

        jarInputStream.close();

        return jarSize;
    }
View Full Code Here

        if (state.exception != null) {
            return;
        }

        try {
            state.storage = new RandomAccessStream();

            state.installInfo.authPath =
                verifier.verifyJar(state.storage, info.jarFilename);

            if (state.listener != null) {
View Full Code Here

     *
     * @exception IOException is thrown if any error prevents the download
     *            of the JAD
     */
    protected byte[] downloadJAD() throws IOException {
        RandomAccessStream jadInputStream;
        ByteArrayOutputStream bos = new ByteArrayOutputStream(CHUNK_SIZE);
        String jadFilename = getUrlPath(info.jadUrl);

        state.beginTransferDataStatus = DOWNLOADING_JAD;
        state.transferStatus = DOWNLOADED_1K_OF_JAD;

        jadInputStream = new RandomAccessStream();
        jadInputStream.connect(jadFilename, Connector.READ);

        transferData(jadInputStream.openInputStream(), bos, CHUNK_SIZE);

        jadInputStream.close();

        return bos.toByteArray();
    }
View Full Code Here

     * @exception IOException is thrown if any error prevents the download
     *   of the JAR
     */
    protected int downloadJAR(String filename) throws IOException {
        int jarSize;
        RandomAccessStream jarInputStream, jarOutputStream;
        String jarFilename = getUrlPath(info.jarUrl);

        // Open source (jar) file
        jarInputStream = new RandomAccessStream();
        jarInputStream.connect(jarFilename, Connector.READ);

        // Open destination (temporary) file
        jarOutputStream = new RandomAccessStream();
        jarOutputStream.connect(filename,
                                RandomAccessStream.READ_WRITE_TRUNCATE);

        // transfer data
        state.beginTransferDataStatus = DOWNLOADING_JAR;
        state.transferStatus = DOWNLOADED_1K_OF_JAR;

        jarSize = transferData(jarInputStream.openInputStream(),
                               jarOutputStream.openOutputStream(), CHUNK_SIZE);

        jarInputStream.close();
        jarOutputStream.disconnect();

        return jarSize;
    }
View Full Code Here

     * @return object that contains access control information or null if
     * this information doesn't exist or contains errors.
     */
    public static ACSlot load(int slotNum) {

        RandomAccessStream storage;
        InputStream permIS;

        try {
            storage = new RandomAccessStream(classSecurityToken);
            storage.connect(File.getStorageRoot(Constants.INTERNAL_STORAGE_ID) +
          "acl_" + slotNum, Connector.READ);
            permIS = storage.openInputStream();
        } catch (IOException e) {
            return null;
        }

        try {
            ACSlot f = new ACSlot();
            f.init(new ACLFileReader(new InputStreamReader(permIS)));
            return f;
        } catch (Exception e) {
            System.out.println("Error reading ACList " + e);
        } finally {
            try {
                storage.disconnect();
            } catch (Exception e) {
                // nothing we can do.
            }
        }
        return null;
View Full Code Here

        String[] extraFieldValues = new String[3];
        int jarSize;
        String locale;
        String prof;
        int space;
        RandomAccessStream jarOutputStream = null;
        OutputStream outputStream = null;

        parsedUrl = new HttpUrl(info.jarUrl);
        if (parsedUrl.authority == null && info.jadUrl != null) {
            // relative URL, add the JAD URL as the base
            try {
                parsedUrl.addBaseUrl(info.jadUrl);
            } catch (IOException e) {
                postInstallMsgBackToProvider(
                    OtaNotifier.INVALID_JAD_MSG);
                throw new InvalidJadException(
                         InvalidJadException.INVALID_JAR_URL);
            }

            url = parsedUrl.toString();

            // The JAR URL saved to storage MUST be absolute
            info.jarUrl = url;
        } else {
            url = info.jarUrl;
        }

        jarOutputStream = new RandomAccessStream();
        jarOutputStream.connect(filename,
                                RandomAccessStream.READ_WRITE_TRUNCATE);
        outputStream = jarOutputStream.openOutputStream();

        prof = System.getProperty(MICROEDITION_PROFILES);
        space = prof.indexOf(' ');
        if (space != -1) {
            prof = prof.substring(0, space);
        }

        extraFieldKeys[0] = "User-Agent";
        extraFieldValues[0] = "Profile/" + prof
                              + " Configuration/" +
                              System.getProperty(MICROEDITION_CONFIG);

        extraFieldKeys[1] = "Accept-Charset";
        extraFieldValues[1] = "UTF-8, ISO-8859-1";

        /* locale can be null */
        locale = System.getProperty(MICROEDITION_LOCALE);
        if (locale != null) {
            extraFieldKeys[2] = "Accept-Language";
            extraFieldValues[2] = locale;
        }

        try {
            state.beginTransferDataStatus = DOWNLOADING_JAR;
            state.transferStatus = DOWNLOADED_1K_OF_JAR;
            jarSize = downloadResource(url, extraFieldKeys, extraFieldValues,
                         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.INVALID_JAR_URL:
            case InvalidJadException.JAR_SERVER_NOT_FOUND:
            case InvalidJadException.JAR_NOT_FOUND:
            case InvalidJadException.INVALID_JAR_TYPE:
                postInstallMsgBackToProvider(
                    OtaNotifier.INVALID_JAR_MSG);
                break;

            default:
                // for safety/completeness.
                if (Logging.REPORT_LEVEL <= Logging.ERROR) {
                    Logging.report(Logging.ERROR, LogChannels.LC_AMS,
                    "Installer InvalidJadException: " + ije.getMessage());
                }
                break;
            }

            throw ije;
        } finally {
            try {
                jarOutputStream.disconnect();
            } catch (Exception e) {
                 if (Logging.REPORT_LEVEL <= Logging.WARNING) {
                     Logging.report(Logging.WARNING, LogChannels.LC_AMS,
                     "disconnect  threw a  Exception");
                 }
View Full Code Here

TOP

Related Classes of com.sun.midp.io.j2me.storage.RandomAccessStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.