如何在J2ME蓝牙OBEX中实现ACTION(移动/重命名,设置权限)操作?

Yar*_*lyk 5 bluetooth java-me jsr82 obex

蓝牙FTP规范说我需要使用ACTION操作,这是一个页面 http://i47.tinypic.com/2425t2v.png

但是ClentSession只提供GET和PUT操作,而javadocs中没有提到任何内容.

这是创建文件操作的外观,非常简单

    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();
    }
Run Code Online (Sandbox Code Playgroud)

问题1:如何使用自定义标头实施ACTION操作以执行移动/重命名和设置权限?没有JSR82 OBEX API就应该可以.请帮我这样做.

问题2:我是否了解如何设置权限?根据OBEX_Errata Compiled For 1.3.pdf(感谢alanjmcf!)

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

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

因此,要设置只读,我应该执行以下操作:

    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?
Run Code Online (Sandbox Code Playgroud)

如果正确,唯一的问题仍然是问题1:如何进行ACTION操作以及如何设置标题.

ala*_*mcf 3

请注意,您引用的蓝牙 FTP 规范中的文本提到了三个标头:ActionId、Name、DestName。因此,您需要添加 1 个 NAME 标头和 1 个 DestName 标头。Jsr-82 显然没有定义该(新)标头的 const,因此引用 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
Run Code Online (Sandbox Code Playgroud)

所以创建以下内容等(我的Java有点生疏)

static final int DEST_NAME = 0x15;
Run Code Online (Sandbox Code Playgroud)

并在您的代码中使用它。

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

我正在从“OBEX_Errata Compiled For 1.3.pdf”中阅读此内容。IrDA 确实对规格收费,但现在似乎根据要求提供(http://www.irda.org)。索取最新 OBEX 规范 (1.5 IIRC) 的副本。我自己已经这样做了,但还没有得到回复。或者您可以尝试用谷歌搜索“移动/重命名对象操作”来获取“1.3 勘误表”PDF。

无论如何,如果 Java 阻止您使用新的操作码(仅允许 GET 和 PUT)并且还阻止您使用新的 HeaderId 值,那么您无论如何都无法继续。:-( *(他们没有理由这样做,因为 HeaderId 对其包含的数据类型进行编码)。

再次查看 Java API 后,我看不到任何通过 ClientSession 发送任意命令的方法。您必须手动构建数据包,连接到 OBEX 服务,然后通过该连接发送和接收数据包。构建数据包并不太困难......