j2me netbeans - 并行数据传输(需要概述想法)
我是 j2me 移动应用程序的新手。我有一个大学项目要在一个月内完成。我需要一些关于如何完成它的基本想法。我正在使用 Netbeans 6.8 j2me 平台。 我必须创建源、目的地和许多中间节点(手机)。必须通过几个中间节点将文件从源发送到目的地(使用蓝牙)。文件可以被分割成块,也可以在任何级别上细分。
http://imageshack.us/photo/my-images/692/parallelism。 jpg/
它应该是这样工作的:
最初,源通过多个路径将类的简单对象(存在于所有节点中)发送到目的地。每个节点都将通过包含其蓝牙地址来更新对象并将其传递到下一个节点。当它到达目的地时,相同的对象被发送回源。源识别一些最佳路径并使用它们进行文件传输。
源将文件分割并将它们发送到最近的节点。中间节点也可以分割并发送分割后的部分。
当所有部分到达目的地时,它们会被连接起来并重建文件。
我为源节点、目标节点和中间节点创建了单独的 netbeans 项目。 分割:我通过将文件转换为字节数组并使用文件连接和创建文件来成功分割。输出流
public void splitfiles(int len) { String url="file:///root1/testfile.jpg"; // int 长度 = 102400; 字节缓冲区[] = 新字节[大小]; 整数计数=0; 尝试 { FileConnection fconi = (FileConnection)Connector.open(url,Connector.READ); 输入流 fis = fconi.openInputStream(); 而(真) { int i = fis.read(缓冲区, 0, len); //创建大小为“len”字节的字节数组 如果(我==-1) 休息; ++计数; 字符串文件名=“file:///root1/testfile.part”+计数; FileConnection fcono = (FileConnection)Connector.open(文件名,Connector.READ_WRITE); if (!fcono.exists()) fcono.create(); OutputStream fos = fcono.openOutputStream(); fos.write(缓冲区, 0, i); //从字节数组“缓冲区”创建文件 fos.close(); fcono.close(); } } 捕获(异常 e) { } }
请告诉我如何重新加入文件。(我使用 j2me 中不存在的 java 类“RandomAcessFile”重新加入它们)。 我尝试了以下方式
while(number of chunks)
{
read a single file in inputstream (files are read one after the other)
copy it to a byte array and flush inputstream
write it to ouputstream
}
copy outputstream to a file
flush outputstream
想法
- 请给我一些关于如何重新加入 j2me 中的块
- 如何通过蓝牙传递类的对象的
I am new to j2me Mobile Applications. I have a college project to be done within a month. I need some basic idea of how it can be done. I am using Netbeans 6.8 j2me platform.
I have to create source, destination and many intermediate nodes(mobile phones). A file has to be sent(am using Bluetooth) from source to destination via several intermediate nodes. The file can be split into chunks and can also be sub-divided at any level.
http://imageshack.us/photo/my-images/692/parallelism.jpg/
This is how it should work:
Initially, the source sends simple objects of a Class(present in all nodes) to destination via several paths. Every node will be updating the object by including its Bluetooth address and passes it to the next node. When it reaches the destination, the same object is sent back to the source. The source identifies some of the optimal paths and uses them for file transfer.
The source splits the file and send them to the nearest nodes. The intermediate nodes can also split and send the divided parts.
When all the parts reach the destination, they are joined and the file is reconstructed.
I created separate netbeans project for source, destination and intermediate node.
Splitting : I did splitting successfully by converting the file into byte array and creating files using File connection & outputstreampublic void splitfiles(int len) { String url="file:///root1/testfile.jpg"; // int len = 102400; byte buffer[] = new byte[size]; int count = 0; try { FileConnection fconi = (FileConnection)Connector.open(url,Connector.READ); InputStream fis = fconi.openInputStream(); while (true) { int i = fis.read(buffer, 0, len); //creating byte array of size "len" bytes if (i == -1) break; ++count; String filename ="file:///root1/testfile.part" + count; FileConnection fcono = (FileConnection)Connector.open(filename,Connector.READ_WRITE); if (!fcono.exists()) fcono.create(); OutputStream fos = fcono.openOutputStream(); fos.write(buffer, 0, i); //creating files out of byte array "buffer" fos.close(); fcono.close(); } } catch(Exception e) { } }
Please tell me how to rejoin the files.(I rejoined them using java class "RandomAcessFile" which is not present in j2me).
I tried in the following way
while(number of chunks)
{
read a single file in inputstream (files are read one after the other)
copy it to a byte array and flush inputstream
write it to ouputstream
}
copy outputstream to a file
flush outputstream
Please give me some idea about
- how to rejoin the chunks in j2me
- How to pass object of a class via bluetooth
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论