Package javax.microedition.io.file

Examples of javax.microedition.io.file.FileConnection


                    if (resource) {
                        is = TinyGoMIDlet.class.getResourceAsStream(path);
                        if (is == null)
                            throw new IOException(T._("Unable to open resource ") + path);
                    } else {
                        FileConnection fc = (FileConnection) Connector.open("file://localhost/" + path);
                        if (!fc.exists())
                            throw new IOException(T._("File ") + path + T._(" doesn't exists!"));
                        is = fc.openDataInputStream();
                    }

                    // Read and parse file in main thread. It's running too slow in parallel!
                    //display.callSerially(new Runnable() {
                        //public void run() {
View Full Code Here


                try {
                    //#ifdef debug
                    System.out.println("Writing " + path);
                    System.out.println(SGFWriter.toString(game.kifuHead()));
                    //#endif
                    FileConnection fc = (FileConnection) Connector.open("file://localhost/" + path);
                    OutputStream os = fc.openDataOutputStream();
                    OutputStreamWriter writer = new OutputStreamWriter(os);
                    SGFWriter.write(writer, game.kifuHead());
                    writer.close();
                    os.close();
                    //#ifdef debug
View Full Code Here

                    if (resource) {
                        is = path.getClass().getResourceAsStream(path);
                        if (is == null)
                            throw new IOException(T._("Unable to open resource ") + path);
                    } else {
                        FileConnection fc = (FileConnection) Connector.open("file://localhost/" + path);
                        if (!fc.exists())
                            throw new IOException(T._("File ") + path + T._(" doesn't exists!"));
                        is = fc.openDataInputStream();
                    }

                    // Read and parse file in main thread. It's running too slow in parallel!
                    display.callSerially(new Runnable() {
                        public void run() {
View Full Code Here

                try {
                    //#ifdef debug
                    System.out.println("Writing " + path);
                    System.out.println(SGFWriter.toString(game.kifuHead()));
                    //#endif
                    FileConnection fc = (FileConnection) Connector.open("file://localhost/" + path);
                    OutputStream os = fc.openDataOutputStream();
                    OutputStreamWriter writer = new OutputStreamWriter(os);
                    SGFWriter.write(writer, game.kifuHead());
                    writer.close();
                    os.close();
                    //#ifdef debug
View Full Code Here

        wc.setProgress(0);
        display.setCurrent(wc);

        try {
            Enumeration e;
            FileConnection currDir = null;
            List browser = createBrowser();

            if (MEGA_ROOT.equals(currDirName)) {
                e = FileSystemRegistry.listRoots();
            } else {
                currDir = (FileConnection) Connector.open("file://localhost/"
                        + currDirName);
                e = currDir.list();
                // not root - draw UP_DIRECTORY
                browser.append(UP_DIRECTORY, dirIcon);
            }

            while (e.hasMoreElements()) {
                String fileName = (String) e.nextElement();
                if (fileName.charAt(fileName.length() - 1) == FilePath.separatorChar)
                    browser.append(fileName, dirIcon);
                else if (fileName.toLowerCase().endsWith(".sgf"))
                    browser.append(fileName, sgfFileIcon);
                else if (fileName.toLowerCase().endsWith(".sgfi"))
                    browser.append(fileName, sgfiFileIcon);
                else
                    browser.append(fileName, fileIcon);
            }

            if (currDir != null)
                currDir.close();

            display.setCurrent(browser);
        } catch (IOException e) {
            //#if debug
            e.printStackTrace();
View Full Code Here

    void showProperties(String fileName) {
        try {
            if (fileName.equals(UP_DIRECTORY))
                return;

            FileConnection fc = (FileConnection) Connector.open("file://localhost/" + currDirName + fileName);
            if (!fc.exists())
                throw new IOException(T._("File does not exists."));

            Form props = new Form(T._("Properties") + ": " + fileName);
            props.addCommand(backToBCommand);
            props.setCommandListener(this);

            props.append(new StringItem(T._("Location"), currDirName));
            props.append(new StringItem(T._("Type"), fc.isDirectory() ? T._("Directory") : T._("Regular File")));
            props.append(new StringItem(T._("Size"), Long.toString((fc.isDirectory() ? fc.directorySize(true) : fc.fileSize()))));
            props.append(new StringItem(T._("Modified"), myDate(fc.lastModified())));

            ChoiceGroup attrs = new ChoiceGroup(T._("Attributes"), Choice.MULTIPLE, attrList, null);
            attrs.setSelectedFlags(new boolean[] { fc.canRead(), fc.canWrite(), fc.isHidden() });
            props.append(attrs);

            if (fileName.toLowerCase().endsWith(".sgf"))
                try {
                    StringBuffer sb = new StringBuffer();
                    InputStream is = fc.openInputStream();
                    SGFParser parser = new SGFParser(new InputStreamReader(is));
                    SGFNode head = parser.parseHead();
                    is.close();
                    for (Enumeration e = head.getProperties(); e.hasMoreElements(); ) {
                        sb.append(e.nextElement().toString());
                        sb.append("\n");
                    }
                    props.append(new StringItem(T._("SGF Header"), sb.toString()));
                } catch (Exception e) {
                }

            fc.close();
            display.setCurrent(props);
        } catch (Exception e) {
            Alert alert = new Alert(T._("Error!"), T._("Can't access file ") + fileName
                    + T._(" in directory ") + currDirName + "\n" + T._("Exception: ")
                    + e.getMessage(), null, AlertType.ERROR);
View Full Code Here

        }
    }

    void deleteFile(String fileName) {
        try {
            FileConnection fc = (FileConnection) Connector.open("file:///"
                    + currDirName + fileName);
            fc.delete();
        } catch (Exception e) {
            Alert alert = new Alert(T._("Error!"), T._("Can not access/delete file ")
                    + fileName + T._(" in directory ") + currDirName + "\n"
                    + T._("Exception: ") + e.getMessage(), null, AlertType.ERROR);
            alert.setTimeout(Alert.FOREVER);
View Full Code Here

        }).start();
    }

    private void checkDeleteFolder(String folderName) {
        try {
            FileConnection fcdir = (FileConnection) Connector
                    .open("file://localhost/" + currDirName + folderName);
            Enumeration content = fcdir.list("*", true);
            // only empty directory can be deleted
            if (!content.hasMoreElements()) {
                fcdir.delete();
                showCurrDir();
            } else {
                Alert cantDeleteFolder = new Alert(T._("Error!"),
                        T._("Can not delete The non-empty folder: ") + folderName,
                        null, AlertType.ERROR);
View Full Code Here

        display.setCurrent(creator);
    }

    void createFile(String newName, boolean isDirectory) {
        try {
            FileConnection fc = (FileConnection) Connector.open("file://localhost/"
                    + currDirName + newName);
            if (isDirectory) {
                fc.mkdir();
            } else {
                fc.create();
            }
            fc.close();
            showCurrDir();
        } catch (Exception e) {
            String s = T._("Can not create file ") + newName;
            if (e.getMessage() != null && e.getMessage().length() > 0) {
                s += "\n" + e;
View Full Code Here

    public int addPath(String path, boolean rescan) throws IOException {
        System.out.println("Adding path to DB " + path);
        int probCnt = problems.size();

        if (path.endsWith(".sgfi")) {
            FileConnection fc = (FileConnection) Connector.open(
                    "file://localhost/" + path);
            readIndex(path, fc.openInputStream(), false);
        } else {
            rescan |= paths.indexOf(path) < 0;
            if (rescan) {
                removePath(path);
                path = addPath(path);
                FileConnection fc = (FileConnection) Connector.open(
                        "file://localhost/" + path);
                if (fc.isDirectory())
                    addDir(path, fc, path);
                else
                    addProblems(path, null, fc.openInputStream(), false);
            }
        }
        return problems.size() - probCnt;
    }
View Full Code Here

TOP

Related Classes of javax.microedition.io.file.FileConnection

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.