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 Developer
Posts: 8
Registered: ‎11-13-2008
My Device: Not Specified
Accepted Solution

EOFException while downloading file from Bluetooth FTP server

Hello, I am trying to develop an app that downloads a file from a Bluetooth FTP server. If I use this code to download a file-list works fine, but if I use the same code to download a real file it doesn't. I have tried with text plain, image, video (mp4 and 3gp) and audio with the same result. If I install my app in a Nokia (N95) or a Motorola (K3) works perfect, but I can't make it work on my Blackberry 8310
The problem in the BlackBerry is an EOFException while reading the first byte, no -1 is returned to indicate the end of file but an EOFException. (BlackBerry Handheld Software v4.2.2.173)


This is the code to get the InputStream:



public InputStream getFileInputStream(ClientSession conn, Operation op, String stFile, String stType) throws IOException {
InputStream inputStream = null;
byte[] FBUUID = {(byte) 0xF9, (byte) 0xEC, (byte) 0x7B, (byte) 0xC4, (byte) 0x95,
(byte) 0x3C, (byte) 0x11, (byte) 0xD2, (byte) 0x98, (byte) 0x4E, (byte) 0x52, (byte) 0x54,
(byte) 0x00, (byte) 0xDC, (byte) 0x9E, (byte) 0x09 };
String file = stFile;
String type = stType;
if (file==null) file="";
if (type==null) type="";
//Prepare the headers for the OBEX commands
HeaderSet header = conn.createHeaderSet();
header.setHeader(HeaderSet.TARGET, FBUUID);
//Send OBEX Connect
HeaderSet response = conn.connect(header);
//In order to go the desired folder the OBEX SETPATH command is beeing used
//Prepare the header for the SETPATH commad
header = conn.createHeaderSet();
//folder_name is set to the name of the desired folder
//if left blank the root folder will be used
String folder_name = "";
header.setHeader(HeaderSet.NAME, folder_name);
//Send the SETPATH command
HeaderSet result = conn.setPath(header, false, false);

//Prepare the header for the GET command
header = conn.createHeaderSet();
header.setHeader(HeaderSet.NAME, file);
header.setHeader(HeaderSet.TYPE, type);
op = conn.get(header);
//The selected file will be send to the operation's input stream
inputStream = op.openInputStream();
return inputStream;



And the call:


InputStream in = getFileInputStream(conn, op, "text.txt", "text/plain");



The same call that works perfect for file-list (in BlackBerry too):


InputStream in = getFileInputStream(conn, op, "", "x-obex/folder-listing");


This call produces an xml file that can be read perfectly by any phone.



Any help is much appreciated!


New Developer
Posts: 8
Registered: ‎11-13-2008
My Device: Not Specified

Re: EOFException while downloading file from Bluetooth FTP server

More data:

I've seen that the problem is that the BlackBerry remains waiting for data (reads 0). If I use an InputStreamReader for reading an XML file everything works fine, but if I use an InputStream the problems appear. This is the code that I use to read:



InputStream in = getFileInputStream(conn, op, "", "x-obex/folder-listing");
// This should in reality read all incoming data String encoding = System.getProperty("microedition.encoding"); testForm.append("Encoding: "+encoding); ByteArrayOutputStream baos = new ByteArrayOutputStream (); byte [] buf = new byte [256]; int i = 0; while ( (i = in.read(buf)) > -1 ) { testForm.append(i+";"); baos.write(buf, 0, i); } baos.flush(); byte [] result = baos.toByteArray(); baos.close(); String utfString = new String(result, "UTF-8");

If I replace "UTF-8" for encoding I get the same result because the app remains freezed reading 0.The same code in a Nokia N95 gets the codes 256, 256, 97 and finally the XML file. In BlackBerry gets 256, 256, 97 and infinite 0's.

Is there any way to force reading the file?




New Developer
Posts: 8
Registered: ‎11-13-2008
My Device: Not Specified

Re: EOFException while downloading file from Bluetooth FTP server

Solved. The problem was to use >-1 instead of !=-1 Smiley Very Happy