Package blackberry.io

Examples of blackberry.io.FileConnectionWrapper


     * @return a list of directory names
     */

    public Object execute( Object thiz, Object[] args ) throws Exception {
        String[] list = null;
        FileConnectionWrapper fConnWrap = null;

        try {
            fConnWrap = new FileConnectionWrapper( args[ 0 ].toString() );
            Enumeration fileEnum = fConnWrap.list();

            int count = 0;
            String fileName;

            while( fileEnum.hasMoreElements() ) {
                fileName = (String) fileEnum.nextElement();
                if( fileName.charAt( fileName.length() - 1 ) == '/' ) { // Is directory
                    count++;
                }
            }

            fileEnum = fConnWrap.list();
            list = new String[ count ];

            int i = 0;
            while( fileEnum.hasMoreElements() ) {
                fileName = (String) fileEnum.nextElement();
                if( fileName.charAt( fileName.length() - 1 ) == '/' ) {// Is directory
                    list[ i++ ] = fileName;
                }
            }

        } finally {
            if( fConnWrap != null ) {
                fConnWrap.close();
            }
        }
        return list;
    }
View Full Code Here


     *            IOException will be thrown if 1. src file does not yet exist,
     *            or the src path is to an directory; if reading is asynchronous,
     *            no exceptions will be thrown when an error occurs
     */
    public Object execute( Object thiz, Object[] args ) throws Exception {
        FileConnectionWrapper fConnWrap = new FileConnectionWrapper( args[ 0 ].toString() );
        fConnWrap.openDataInputStream();

        if( args.length == 2 || ( args.length == 3 && ( (Boolean) args[ 2 ] ).booleanValue() ) ) { // Async read
            new Thread( new AsyncRead( this, fConnWrap, args[ 0 ].toString(), (ScriptableFunction) args[ 1 ] ) ).start();
        } else { // Sync read
            read( this, fConnWrap, args[ 0 ].toString(), (ScriptableFunction) args[ 1 ] );
View Full Code Here

     * @return a list of file names
     */

    public Object execute( Object thiz, Object[] args ) throws Exception {
        String[] list = null;
        FileConnectionWrapper fConnWrap = null;
        try {
            fConnWrap = new FileConnectionWrapper( args[ 0 ].toString() );
            Enumeration fileEnum = fConnWrap.list();

            int count = 0;
            String fileName;

            while( fileEnum.hasMoreElements() ) {
                fileName = (String) fileEnum.nextElement();
                if( fileName.charAt( fileName.length() - 1 ) != '/' ) { // Is a file
                    count++;
                }
            }

            fileEnum = fConnWrap.list();
            list = new String[ count ];

            int i = 0;
            while( fileEnum.hasMoreElements() ) {
                fileName = (String) fileEnum.nextElement();
                if( fileName.charAt( fileName.length() - 1 ) != '/' ) {// Is a file
                    list[ i++ ] = fileName;
                }
            }

        } finally {
            if( fConnWrap != null ) {
                fConnWrap.close();
            }
        }
        return list;
    }
View Full Code Here

     *            args[0] : complete URL path of the file.
     *
     *            IOException will be thrown if src file does not yet exist, or the src path is a directory
     */
    public Object execute( Object thiz, Object[] args ) throws Exception {
        FileConnectionWrapper fConnWrap = null;
        FilePropertiesObject fileProObj = null;

        try {
            fConnWrap = new FileConnectionWrapper( args[ 0 ].toString() );
            ExtendedFileConnection fConn = (ExtendedFileConnection) fConnWrap.getFileConnection();

            Boolean isReadonly = new Boolean( !fConn.canWrite() );
            Boolean isHidden = new Boolean( fConn.isHidden() );
            Double size = new Double( fConn.fileSize() );
            Date dateModified = new Date( fConn.lastModified() );

            int dotIndex = ( args[ 0 ].toString() ).lastIndexOf( (int) '.' );
            String fileExtension = "";
            if( dotIndex >= 0 ) {
                fileExtension = ( args[ 0 ].toString() ).substring( dotIndex );
            }

            String directory = "file://" + fConn.getPath();
            String mimeType = MIMETypeAssociations.getMIMEType( fConn.getName() );
            if( mimeType == null ) {
                mimeType = "";
            }

            // get the character encoding by scanning the first 2-4 bytes
            byte[] data = null;
            if( size.intValue() >= 2 ) {
                data = new byte[ 4 ];
                DataInputStream dis = fConnWrap.openDataInputStream();
                dis.read( data, 0, 4 ); // IOException may be thrown
            }
            String encoding = getEncoding( data );
            fileProObj = new FilePropertiesObject( isReadonly, isHidden, size, null, dateModified, fileExtension, directory,
                    mimeType, encoding );

        } finally {
            if( fConnWrap != null ) {
                fConnWrap.close();
            }
        }

        return fileProObj;
    }
View Full Code Here

     *            Ex: To create a new dir "foo" in "file:///SDCard/BlackBerry/documents/" :
     *            createNewDir("file:///SDCard/BlackBerry/documents/foo/");
     *
     */
    public Object execute( Object thiz, Object[] args ) throws Exception {
        FileConnectionWrapper fileConnWrap = null;

        try {
            fileConnWrap = new FileConnectionWrapper( args[ 0 ].toString() );
            fileConnWrap.getFileConnection().mkdir();
        } finally {
            if( fileConnWrap != null ) {
                fileConnWrap.close();
            }
        }
        return UNDEFINED;
    }
View Full Code Here

     *            IOException will be thrown if source file does not yet exist, or the source path is to an directory or if
     *            destination file already exist
     */

    public Object execute( Object thiz, Object[] args ) throws Exception {
        FileConnectionWrapper fconnWrapIn = null;
        DataInputStream dis = null;
        FileConnectionWrapper fconnWrapOut = null;
        DataOutputStream dos = null;

        try {
            fconnWrapIn = new FileConnectionWrapper( args[ 0 ].toString() );
            dis = fconnWrapIn.openDataInputStream();

            fconnWrapOut = new FileConnectionWrapper( args[ 1 ].toString() );

            if( fconnWrapOut.isDirectory() ) {
                throw new FileIOException( FileIOException.NOT_A_FILE );
            }

            fconnWrapOut.create();
            dos = fconnWrapOut.openDataOutputStream();

            for( int b = dis.read(); b != -1; b = dis.read() ) {
                dos.write( b );
            }

            dos.flush();
        } finally {
            if( fconnWrapIn != null ) {
                fconnWrapIn.close();
            }
            if( fconnWrapOut != null ) {
                fconnWrapOut.close();
            }
        }
        return UNDEFINED;
    }
View Full Code Here

     *
     *            IOException will be thrown if src file does not yet exist or if the src path is a directory
     *
     */
    public Object execute( Object thiz, Object[] args ) throws Exception {
        FileConnectionWrapper fConnWrap = null;
        try {
            fConnWrap = new FileConnectionWrapper( args[ 0 ].toString() );

            if( fConnWrap.isDirectory() ) {
                throw new FileIOException( FileIOException.NOT_A_FILE );
            }

            fConnWrap.delete();
        } finally {
            if( fConnWrap != null ) {
                fConnWrap.close();
            }
        }
        return UNDEFINED;
    }
View Full Code Here

TOP

Related Classes of blackberry.io.FileConnectionWrapper

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.