Examples of RandomAccessStream


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

     *
     * @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

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

     * @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

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

     * @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

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

        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

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

    private static byte[] getResourceImpl(SecurityToken token,
            String resourceFilename) {
        token.checkIfPermissionAllowed(Permissions.MIDP);

        byte[] resourceBuffer = null;
        RandomAccessStream stream = new RandomAccessStream(token);

        try {
            stream.connect(resourceFilename, Connector.READ);
            resourceBuffer = new byte[stream.getSizeOf()];
            stream.readBytes(resourceBuffer, 0, resourceBuffer.length);
        } catch (java.io.IOException e) {
            resourceBuffer = null;
        } finally {
            try {
                stream.disconnect();
            } catch (java.io.IOException ignored) {
            }
        }

        return resourceBuffer;
View Full Code Here

Examples of ij.io.RandomAccessStream

            return;
        }
        ImageIcon tmpIcon = null;
        try {

            RandomAccessStream stream = new RandomAccessStream(
                    new RandomAccessFile(file, "r"));
            if (reader.isLSMfile(stream)) {
                ImagePlus imp[] = reader.open(file.getParent(), file.getName(), false, false, true);
                if (imp != null && imp.length>0)
                    tmpIcon = new ImageIcon(imp[0].getImage());
View Full Code Here

Examples of ij.io.RandomAccessStream

    ImagePlus[] imp = null;
    RandomAccessFile file;
    LsmFileInfo lsm;
    try {
      file = new RandomAccessFile(new File(directory, filename), "r");
      RandomAccessStream stream = new RandomAccessStream(file);
      lsm = new LsmFileInfo(masterModel);
      lsm.fileName = filename;
      lsm.directory = directory;
      if (isLSMfile(stream)) {
        // read first image directory
        ImageDirectory imDir = readImageDirectoy(stream, 8, thumb);
        lsm.imageDirectories.add(imDir);
        while (imDir.OFFSET_NEXT_DIRECTORY != 0) {
          imDir = readImageDirectoy(stream,
              imDir.OFFSET_NEXT_DIRECTORY, thumb);
          lsm.imageDirectories.add(imDir);
        }
        // printImDirData(lsm);
        imp = open(stream, lsm, verbose, thumb);
        stream.close();
        if (showInfoFrames)
          showEventList(lsm);
      } else
        IJ.error("Not a valid lsm file");
    } catch (FileNotFoundException e) {
View Full Code Here

Examples of ij.io.RandomAccessStream

    ImagePlus[] imp = null;
    RandomAccessFile file;
    LsmFileInfo lsm;
    try {
      file = new RandomAccessFile(new File(directory, filename), "r");
      RandomAccessStream stream = new RandomAccessStream(file);
      lsm = new LsmFileInfo();
      lsm.fileName = filename;
      lsm.directory = directory;
      if (isLSMfile(stream)) {
        ImageDirectory imDir = readImageDirectoy(stream, 8, thumb);
        lsm.imageDirectories.add(imDir);
        while (imDir.OFFSET_NEXT_DIRECTORY != 0) {
          imDir = readImageDirectoy(stream,
              imDir.OFFSET_NEXT_DIRECTORY, thumb);
          lsm.imageDirectories.add(imDir);
        }
        imp = open(stream, lsm, verbose, thumb);
        stream.close();
      } else
        IJ.error("Not a valid lsm file");
    } catch (FileNotFoundException e) {
      IJ.error("File not found");
      e.printStackTrace();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.