Examples of FileConnection


Examples of javax.microedition.io.file.FileConnection

    }

    public boolean existsData() throws IOException {
        if (rootPrefix == null)
            return false;
        final FileConnection conn = (FileConnection) Connector.open(rootPrefix + "list");
        try {
            return conn.exists();
        } finally {
            conn.close();
        }
    }
View Full Code Here

Examples of javax.microedition.io.file.FileConnection

        }
    }

    public StoredFileInfo getFileInfo(final String fileName) throws IOException {
        final StoredFileInfo result = new StoredFileInfo();
        final FileConnection conn = (FileConnection) Connector.open(rootPrefix + fileName);
        try {
            if (conn.exists()) {
                result.fileLength = conn.fileSize();
                final InputStream in = conn.openInputStream();
                try {
                    final byte[] data = BaseStorage.readFromInputStream(in);
                    result.fileCRC = CRC32.calculate(data);
                } finally {
                    in.close();
                }
            } else {
                result.fileLength = -1;
            }
        } finally {
            conn.close();
        }
        return result;
    }
View Full Code Here

Examples of javax.microedition.io.file.FileConnection

        }
        return result;
    }

    public void saveFile(String fileName, byte[] data) throws IOException {
        final FileConnection conn = (FileConnection) Connector.open(rootPrefix + fileName);
        try {
            if (!conn.exists()) {
                conn.create();
            }
            final OutputStream out = conn.openOutputStream();
            try {
                out.write(data);
                out.flush();
            } finally {
                out.close();
            }
        } finally {
            conn.close();
        }
    }
View Full Code Here

Examples of javax.microedition.io.file.FileConnection

                    if (Options.getInstance().useFileApi) {

                        Runnable saveFile = new Runnable() {
                            public void run() {
                                FileConnection fileConn;
                                try {
                                    fileConn = (FileConnection) Connector.open(fileUrl, Connector.READ_WRITE);

                                    if (!fileConn.exists()) {
                                        fileConn.create();
                                    }
                                    DataOutputStream outputStream = fileConn.openDataOutputStream();
                                    outputStream.write(imageData);
                                    outputStream.close();
                                    fileConn.close();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }
                        };
View Full Code Here

Examples of javax.microedition.io.file.FileConnection

        if (!options.useFileApi) {
            return;
        }
        String url = ("file:///" + options.rootName + dir);
        try {
            FileConnection conn = (FileConnection) Connector.open(url, Connector.READ_WRITE);
            if (!conn.exists()) {
                conn.mkdir();
            } else if (!conn.isDirectory()) {
                CloudGps.setError(url + " exists but is not a directory. Saving tiles will fail.");
            }
        } catch (IOException e) {
            CloudGps.setError(e);
        }
View Full Code Here

Examples of javax.microedition.io.file.FileConnection

        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        String fileName = "GpsLog_" + cal.get(Calendar.YEAR) + "-" + prefixWithZero(month) + "-" + prefixWithZero(day)
                + "_" + prefixWithZero(hour) + "." + prefixWithZero(minute) + "." + prefixWithZero(second) + ".txt";
        try {
            FileConnection fileConn = (FileConnection) Connector.open("file:///" + Options.getInstance().rootName
                    + IOTool.NMEA_LOGS_DIR + "/" + fileName, Connector.WRITE);
            fileConn.create();
            return fileConn.openDataOutputStream();
        } catch (IOException e) {
            CloudGps.setError(e);
        }
        return null;
    }
View Full Code Here

Examples of javax.microedition.io.file.FileConnection

    private static String prefixWithZero(int i) {
        return i < 10 ? "0" + i : "" + i;
    }

    public static String[] listDir(String dirUrl) throws IOException {
        FileConnection fileConn = (FileConnection) Connector.open(dirUrl, Connector.READ);
        Enumeration list = fileConn.list();
        Vector files = new Vector();

        while (list.hasMoreElements()) {
            files.addElement(list.nextElement());
        }
View Full Code Here

Examples of javax.microedition.io.file.FileConnection

                int tries = 0;
                while (inputStream == null) {
                    try {
                        if (options.replayMode) {
                            inputStream = Connector.openInputStream(options.replayFileName);
                            FileConnection conn = (FileConnection) Connector.open(options.replayFileName,
                                    Connector.READ);
                            gpsState.replySize = conn.fileSize();
                            gpsState.replyPosition = 0;
                            conn.close();
                        } else {
                            inputStream = Connector.openInputStream(options.gpsUrl);
                        }
                    } catch (Throwable e) {
                        tries++;
View Full Code Here

Examples of javax.microedition.io.file.FileConnection

     * @param path directory location
     */
    public void directoryWalk(String path) {
        files.removeAllElements();
        try {
            FileConnection fc = (FileConnection) Connector.open(path, Connector.READ);
            Enumeration fl = fc.list("*.jpg", true);
            while(fl.hasMoreElements()) {
                files.addElement((String) fl.nextElement());
            }
            fc.close();
        }
        catch (SecurityException e) {
            System.out.println("SecurityError: " + e.getMessage());
        }
        catch (IOException e) {
View Full Code Here

Examples of javax.microedition.io.file.FileConnection

     *
     * @param fullPath The path of the file
     * @return <code>true</code> if the file exists; <code>false</code> otherwise
     */
    public static boolean exists( String fullPath ) {
        FileConnection con = open( fullPath );
        boolean retval = ( con != null && con.exists() && !con.isDirectory() );
        close( con );

        return retval;
    }
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.