Package javax.microedition.io.file

Examples of javax.microedition.io.file.FileConnection


         */
        protected void onFileAdded( String path ) {
            // invoke callback
            if( path.length() > 0 ) {
                try {
                    FileConnection conn = (FileConnection) Connector.open( "file://" + path );
                    if( conn.exists() ) {
                        // invoke callback for the file
                        new CallbackDispatcherEvent( _context, _callback, new Object[] { path } ).Dispatch();
                    } else {
                        handleError( _errorCallback, new FileNotFoundException( path ) );
                    }
View Full Code Here


        }

        private void dispatchFile( String path ) {
            if( path.length() > 0 ) {
                try {
                    FileConnection conn = (FileConnection) Connector.open( "file://" + path );
                    if( conn.exists() ) {
                        // invoke callback for the file
                        new CallbackDispatcherEvent( _context, _callback, new Object[] { path } ).Dispatch();
                    } else {
                        handleError( _errorCallback, new FileNotFoundException( path ) );
                    }
View Full Code Here

     * Write a WAV Header. See https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ for more info BlackBerry PCM recording
     * is 16bit 8000hz mono
     */
    private void writeWavHeader() throws IOException {
        // Reopen the output file
        FileConnection conn = (FileConnection) Connector.open( _path, Connector.READ_WRITE );
        int size = (int) conn.fileSize();

        // use output stream as it is shown in the sample
        OutputStream o = conn.openOutputStream();

        //*********************************************************************************************************************
        //*****************************************************************************    NAME            Endedness       Size
        //*********************************************************************************************************************
        // RIFF Chunk Descriptor
View Full Code Here

            _player.realize();

            _rcontrol = (RecordControl) _player.getControl( "RecordControl" );

            // Create the output file
            FileConnection conn = (FileConnection) Connector.open( _path, Connector.READ_WRITE );
            if( conn.exists() ) {
                MicrophoneNamespace
                        .handleError( _errorCallback, new IllegalArgumentException( "'" + _path + "' already exists" ) );
                stop();
                return;
            }

            conn.create();

            // use output stream as it is shown in the sample
            _output = conn.openOutputStream();

            // Leave 44 bytes for the WAV header
            if( _type == TYPE_WAV ) {
                for( int i = 0; i < 44; i++ ) {
                    _output.write( 0 );
View Full Code Here

                    try {
                        if( _type == TYPE_WAV ) {
                            writeWavHeader();
                        }

                        FileConnection conn = (FileConnection) Connector.open( _path, Connector.READ );
                        if( conn.exists() ) {
                            // invoke callback for the file
                            new CallbackDispatcherEvent( _completeCallback, new Object[] { _path } ).Dispatch();
                        } else {
                            MicrophoneNamespace.handleError( _errorCallback, new FileNotFoundException( _path ) );
                        }
View Full Code Here

     * Set background of home screen
     * @param filepath - path of image file
     * @throws Exception
     */
    public void setHomeScreenBackground( String filePath ) throws Exception {
        FileConnection fileConnection = null;
        try {
            Connection con = Connector.open( filePath );
            if( con != null && con instanceof FileConnection ) {
                fileConnection = (FileConnection) con;
                if( !fileConnection.exists() || fileConnection.isDirectory() ) {
                    throw new Exception( "Invalid file URI" );
                }
                // set home screen background
                HomeScreen.setBackgroundImage( filePath );
            }
        } finally {
            if( fileConnection != null ) {
                fileConnection.close();
            }
        }
    }
View Full Code Here

                    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 = 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

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.