Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

New Contributor
Posts: 4
Registered: ‎09-28-2011
My Device: all model
My Carrier: Developper

Obex Bluetooth inputStream 4095 bytes limit



we have tried this code to get a stream from a Bluetooth device, in the onPut function extending ServerRequestHandler:



public int onPut(Operation op)
        // Display information about the data received
            // Read the meta data of a received file
        	fileName = (String) op.getReceivedHeaders().getHeader(HeaderSet.NAME);
            InputStream is = op.openInputStream();
            // Read the content of a received file
            byte b[] = new byte[1024];
            int len = 0;
			String content = "";
            while(is.available() > 0 &&(len = is.read(b)) > 0)// 
            	content += new String(b, 0, len);
        catch(IOException ioe)
        return ResponseCodes.OBEX_HTTP_OK;


If we don't use the "is.available" we get the whole file but we have an error on the Bluetooth device and the application hangs.

If we use "is.available" we have a 4025 bytes file only (we need more) but no error on the device and the application is OK.

How can we get the whole file without error ?

We have seen this question many times on this forum but no answers. 

Any help will be appreciated.


Thank you.

Posts: 36
Registered: ‎01-26-2012
My Device: 9900
My Carrier: T-Mobile DE

Re: Obex Bluetooth inputStream 4095 bytes limit

Couple thoughts:


  1. Suggest you change your buffer to 2048 bytes and don’t change – this gives the best results in our experience (and may solve the hanging issue).
  2. Recommend NOT using the available() AP to determine if the file is complete.
    • Instead use the LENGTH header field (which should be mandatory for OPP) to determine how many bytes are expected, and keep a running tally of the read() calls to know when you’ve read the entire incoming file.
    • ALSO exit the loop if read() returns a negative value
  3. Could also be that the sending side is not following strict OPP protocol and thus wouldn’t connect successfully with BlackBerry 7 over the regular OPP channels. Might be helpfull to trace that
  4. Alternatively, you could simply assume that either read() == -1 OR EOFException means you’ve hit the end of the received data, and exit your loop