2012-04-30 20 views
5

蓝牙FTP规范说我需要用行动操作,这里有一个页面 http://i47.tinypic.com/2425t2v.png如何在J2ME蓝牙OBEX中实现ACTION(移动/重命名,设置权限)操作?

ClentSession仅提供get和put操作,并且在javadoc文档只字不提。

这里的创建文件操作的样子,这是很容易

public void create() throws IOException { 
     HeaderSet hs = cs.createHeaderSet(); 
     hs.setHeader(HeaderSet.NAME, file); 
     op = cs.put(hs); 
     OutputStream os = op.openOutputStream(); 
     os.close(); 
     op.close(); 
    } 

问题1:如何实现自定义页眉行动操作进行移动/重命名并设置权限?没有JSR82 OBEX API应该是可能的。请帮助我做到这一点。

问题2: 我了解如何设置权限吗? 据OBEX_Errata编译1.3.pdf

1 http://i45.tinypic.com/2h84led.jpg

2 http://i49.tinypic.com/2wgysmx.png

因此,设置只读,我应该做到以下几点(感谢alanjmcf!):

int a = 0; 

    //byte 0 //zero 
    //byte 1 //user 
    //byte 2 //group 
    //byte 3 //other 

    //set read for user 
    a |= (1 << 7); //8th bit - byte 1, bit 0 -> set to 1 
    // a = 10000000 

    //for group 
    a |= (1 << 15); //16th bit - byte 2, bit 0 -> set to 1 
    // a = 1000000010000000 

    //for other 
    a |= (1 << 23); //24th bit - byte 3, bit 0 -> set to 1 
    // a = 100000001000000010000000 

    //or simply 
    private static final int READ = 8421504 //1000,0000,1000,0000,1000,0000 
    int value = 0 | READ; 

    //========== calculate write constant ========= 
    a = 0; 
    a |= (1 << 8); //write user 
    a |= (1 << 16); //write group 
    a |= (1 << 24); //write other 
    // a = 1000000010000000100000000 
    private static final int WRITE = 16843008 // 1,0000,0001,0000,0001,0000,0000 

    //========= calculate delete constant ========== 
    a = 0; 
    a |= (1 << 9); //delete user 
    a |= (1 << 17); //delete group 
    a |= (1 << 25); //delete other 
    //a = 10000000100000001000000000 
    private static final DELETE = 33686016; //10,0000,0010,0000,0010,0000,0000 

    //========= calculate modify constant ========== 
    a = 0; 
    a |= (1 << (7 + 7)); //modify user 
    a |= (1 << (15 + 7)); //modify group 
    a |= (1 << (23 + 7)); //modify other 
    //a = 1000000010000000100000000000000 
    private static final MODIFY = 1077952512; // 100,0000,0100,0000,0100,0000,0000,0000 


    // now, if i want to set read-write-delete-modify, I will do the following: 
    int rwdm = 0 | READ | WRITE | DELETE | MODIFY; 
    // and put the value to the header... am I right? 

如果对,唯一的问题仍然是问题1:如何使ACTION操作以及如何设置标题。

+0

+1为所有闪亮的图片! –

+1

http://code.google.com/p/blueframe/source/checkout - 也许有些东西 –

+0

@AmigableClarkKant设备交换自己格式的数据。它无法帮助我创建目标设备将识别为OBEX的标头。 –

回答

3

请注意,您从蓝牙FTP规范引用的文本提到了三个标头:ActionId,Name,DestName。所以你需要添加一个NAME标题和一个DestName标题。 JSR-82显然是没有定义的常量为(新的)头,以便从OBEX规格报价:

改性
2.1 OBEX头

HI identifier | Header name | Description 
0x94   Action Id  Specifies the action to be performed (used in ACTION operation) 
0x15   DestName  The destination object name (used in certain ACTION operations) 
0xD6   Permissions 4 byte bit mask for setting permissions 
0x17 to 0x2F Reserved for future use. This range includes all combinations of the upper 2 bits 

所以创建以下等等(我的Java的一个位生锈)

static final int DEST_NAME = 0x15; 

并在你的代码中使用它。

[ADD]作为动作的所有操作(动作)使用ACTION操作! : - ,)这是使用OBEX操作码ACTION而不是PUT或GET等。操作码ACTION的值是0x86

我在读“OBEX_Errata Compiled For 1.3.pdf”。 IrDA收取了规格费用,但现在应要求提供(http://www.irda.org)。要求提供最新的OBEX规格(1.5 IIRC)的副本。我自己也是这么做的,但还没有得到回应。或者你也许可以尝试使用Google的“移动/重命名对象动作”来获得'1.3勘误'PDF。无论如何,如果Java阻止您使用新的操作码(仅允许GET和PUT),并且还阻止您使用新的HeaderId值,那么无论如何您都无法继续操作。 :-(*(当HeaderId对它所包含的数据类型进行编码时,他们没有理由这么做)

在再次查看Java API之后,我看不到任何通过ClientSession发送任意命令的方式。您必须手动构建数据包,连接到OBEX服务,然后通过该连接发送和接收数据包。这也不是难以建立数据包...

+0

但我仍然不知道该怎么做。 –

+0

虽然这个答案被授予,我的问题仍然没有答案。 –