Package net.rim.device.api.util

Examples of net.rim.device.api.util.DataBuffer


    private static int getConfigType( final ServiceRecord record ) {
        return getDataInt( record, 12 );
    }

    private static int getDataInt( final ServiceRecord record, final int type ) {
        DataBuffer buffer = null;
        buffer = getDataBuffer( record, type );

        if( buffer != null ) {
            try {
                return ConverterUtilities.readInt( buffer );
View Full Code Here


    }

    private static DataBuffer getDataBuffer( final ServiceRecord record, final int type ) {
        final byte[] data = record.getApplicationData();
        if( data != null ) {
            final DataBuffer buffer = new DataBuffer( data, 0, data.length, true );
            try {
                buffer.readByte();
            } catch( final EOFException e1 ) {
                return null;
            }
            if( ConverterUtilities.findType( buffer, type ) ) {
                return buffer;
View Full Code Here

    private void handleMessage( PushInputStream inputStream, StreamConnection conn ) {

        EventLogger.logEvent( WidgetProperties.getInstance().getGuid(), ( "handleMessage is called." ).getBytes(), EventLogger.DEBUG_INFO );
       
        DataBuffer db = null;
        try {
            /**
             * Does this need to be synch'd? This should be a single threaded instance that runs autonomously on a port.
             *
             * Might want to call this in the the PushService class to catch IOPortAlreadyBoundException so we can properly throw
             * this back up via JavaScript so the developer realizes that the port they tried to open is unavailable.
             */

            Vector messageQueue = _daemonStore.getMessageQueue();

            // extract the data from the input stream
            db = new DataBuffer();
            byte[] data = new byte[ CHUNK_SIZE ];
            int chunk = 0;
            while( -1 != ( chunk = inputStream.read( data ) ) ) {
                db.write( data, 0, chunk );
            }

            // trim the array - the buffer in DataBuffer grows
            // past the size and fills with empty chars
            db.trim();

            // synchronize this block to avoid race conditions with the queue
            synchronized( messageQueue ) {
                // Create push object, add to queue for callback thread
                PushData pd = new PushData( conn, inputStream, db.getArray() );
                if( _maxQueueCap > 0 ) {
                    if( messageQueue.size() >= _maxQueueCap ) {
                        messageQueue.removeElementAt( 0 );
                    }
                }
View Full Code Here

        messageProcessor.start();

        while( !_stop ) {
            StreamConnection stream = null;
            InputStream input = null;
            DataBuffer db = null;
            try {
                /**
                 * Does this need to be synch'd? This should be a single threaded instance that runs autonomously on a port.
                 *
                 * Might want to call this in the the PushService class to catch IOPortAlreadyBoundException so we can properly
                 * throw this back up via JavaScript so the developer realizes that the port they tried to open is unavailable.
                 */
                synchronized( this ) {
                    _notify = (StreamConnectionNotifier) Connector.open( getURL() );
                }

                while( !_stop ) {
                    // block for data
                    stream = _notify.acceptAndOpen();
                    try {
                        // create input stream
                        input = stream.openInputStream();

                        // extract the data from the input stream
                        db = new DataBuffer();
                        byte[] data = new byte[ CHUNK_SIZE ];
                        int chunk = 0;
                        while( -1 != ( chunk = input.read( data ) ) ) {
                            db.write( data, 0, chunk );
                        }

                        // trim the array - the buffer in DataBuffer grows
                        // past the size and fills with empty chars
                        db.trim();

                        // synchronize this block to avoid race conditions with the queue
                        synchronized( _messageQueue ) {
                            // Create push object, add to queue for callback thread
                            PushData pd = new PushData( stream, input, db.getArray() );
                            _messageQueue.addElement( pd );
                            _messageQueue.notify();
                        }
                    } catch( IOException e1 ) {
                        // a problem occurred with the input stream
View Full Code Here

            ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
           
            BlockDecryptor decryptor = new BlockDecryptor( unformatterEngine, inputStream );
           
            byte[] read = new byte[data.length];
            DataBuffer databuffer = new DataBuffer();
        
            int bytesRead = decryptor.read( read );
            if( bytesRead > 0 ) {
            databuffer.write(read, 0, bytesRead);
            }
           
            byte[] decryptedData = databuffer.toArray();
            return new String(decryptedData);
        }catch( CryptoTokenException e ) {
            StaticDataHelper.log(e.toString());
        } catch (CryptoUnsupportedOperationException e) {
            StaticDataHelper.log(e.toString());
View Full Code Here

            ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
           
            BlockDecryptor decryptor = new BlockDecryptor( unformatterEngine, inputStream );
           
            byte[] read = new byte[data.length];
            DataBuffer databuffer = new DataBuffer();
        
            int bytesRead = decryptor.read( read );
            if( bytesRead > 0 ) {
            databuffer.write(read, 0, bytesRead);
            }
          
            byte[] decryptedData = databuffer.toArray();
            return decryptedData.toString();
        }catch( CryptoTokenException e ) {
            StaticDataHelper.log(e.toString());
        } catch (CryptoUnsupportedOperationException e) {
            StaticDataHelper.log(e.toString());
View Full Code Here

            ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
           
            BlockDecryptor decryptor = new BlockDecryptor( unformatterEngine, inputStream );
           
            byte[] read = new byte[data.length];
            DataBuffer databuffer = new DataBuffer();
        
            int bytesRead = decryptor.read( read );
            if( bytesRead > 0 ) {
            databuffer.write(read, 0, bytesRead);
            }
          
            byte[] decryptedData = databuffer.toArray();
            return decryptedData.toString();
        }catch( CryptoTokenException e ) {
            StaticDataHelper.log(e.toString());
        } catch (CryptoUnsupportedOperationException e) {
            StaticDataHelper.log(e.toString());
View Full Code Here

            ByteArrayInputStream inputStream = new ByteArrayInputStream( data );
           
            BlockDecryptor decryptor = new BlockDecryptor( unformatterEngine, inputStream );
           
            byte[] temp = new byte[10];
            DataBuffer db = new DataBuffer();
            for( ;; ) {
                int bytesRead = decryptor.read( temp );
                if( bytesRead <= 0 ) {
                    break;
                }
                db.write(temp, 0, bytesRead);
            }
           
            byte[] decryptedData = db.toArray();
            return decryptedData.toString();
        }catch( CryptoTokenException e ) {
            StaticDataHelper.log(e.toString());
        } catch (CryptoUnsupportedOperationException e) {
            StaticDataHelper.log(e.toString());
View Full Code Here

        /**
         * @see net.rim.device.api.system.IOPortListener#dataReceived(int)
         */
        public void dataReceived(int length) {
            final DataBuffer db = new DataBuffer();
            int len;

            try {
                final byte[] receiveBuffer = new byte[16380];

                if (length == -1) // Length not available
                {
                    length = receiveBuffer.length;
                }

                // If something was read then add it to the data buffer to
                // send back later.
                synchronized (this) {
                    len = _port.read(receiveBuffer, 0, length);
                }
                if (len != 0) {
                    db.write(receiveBuffer, 0, len);
                    final String data = new String(receiveBuffer, 0, len);
                    message("lowlevelusb: " + data);
                }

                // Wakeup read()
                synchronized (this) {
                    _readQueue.addElement(db.toArray());
                    _dataAvailable = true;
                    this.notify();
                }
            } catch (final IOException ex) {
                throw new RuntimeException(ex.getMessage());
View Full Code Here

            // decryptedData array. It is important to note that for
            // efficiency one would most likely want to use a larger
            // value than 10. We use a small value so that we can
            // demonstrate several iterations through the loop.
            final byte[] temp = new byte[10];
            final DataBuffer db = new DataBuffer();

            for (;;) {
                final int bytesRead = decryptor.read(temp);

                if (bytesRead <= 0) {
                    // We have run out of information to read, bail out of loop
                    break;
                }

                db.write(temp, 0, bytesRead);
            }

            // Now we want to ensure that the decrypted data is the same as the
            // data we passed into the encryptor.
            final byte[] decryptedData = db.toArray();

            final String decryptedText = new String(decryptedData);

            if (Arrays.equals(text.getBytes(), decryptedData)) {
                _statusField
View Full Code Here

TOP

Related Classes of net.rim.device.api.util.DataBuffer

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.