Help: transfering files with obex

Helo, I'm writing an obex server and client, just to transfer files between two computers

Everything seems to go ok, the client connects to the server and starts transfering the file, and the server achieves the file name, size ... but when I go to see the file, the file exists but its length is 0 bytes. This is the code of the server:

java.io.InputStream is = op.openInputStream();

int size;

String name;

size = Integer.parseInt(((Long) op.getReceivedHeaders().getHeader(HeaderSet.LENGTH)).toString());

name = op.getReceivedHeaders().getHeader(HeaderSet.NAME).toString();

File f =new File(name);

FileOutputStream fos =new FileOutputStream(f);

byte b[] =newbyte[size];

int len;

while (is.available() > 0 && (len = is.read(b)) > 0){

fos.write(b, 0, len);

}

updateStatus("[server:] Wrote data to " + f.getAbsolutePath());

updateStatus("Got data bytes " + size +" name " + name +" type " + op.getType());

op.close();

is.close();

fos.close();

Can you help me? Thanks.

[1525 byte] By [ouendana] at [2007-11-26 17:27:56]
# 1
Remove the call to available().Also is this serious?size = Integer.parseInt(((Long) op.getReceivedHeaders().getHeader(HeaderSet.LENGTH)).toString());You are getting a Long, converting it to a String, then parsing the String as an integer. Why all the shenanigans?
ejpa at 2007-7-8 23:55:52 > top of Java-index,Core,Core APIs...