首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

Alljoyn 怎么利用Raw格式传输文件

2012-11-23 
Alljoyn 如何利用Raw格式传输文件这里的利用到了demo中的RawClient和RawService。请参考SDK。下面的是demo中

Alljoyn 如何利用Raw格式传输文件
这里的利用到了demo中的RawClient和RawService。请参考SDK。下面的是demo中传输一个字符串所采用的方式:

if(mStreamUp == true)后面的代码改写为如下的函数即可。

private void doSendFile(){         Log.i(TAG,"doSendFile()");         if(mStreamUp == true){             try{            String filepath = "/sdcard/Teste.jpg";                          file = newFile(filepath);                              mOutputStream.write(getBytesFromFile(file));                 mOutputStream.flush();                                                  }catch(Exception ex) {                 Log.i(TAG,"ERRO writing file "+ex);             }        }      } public byte[] getBytesFromFile(File file) throwsIOException {         Log.i(TAG,"getBytesFromFile()");           InputStream is = newFileInputStream(file);         longlength = file.length();         if(length > Integer.MAX_VALUE) {             System.out.println("Arquivo muito grande");         }         byte[] bytes = newbyte[(int) length];         intoffset = 0;         intnumRead = 0;         while(offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >=0) {             offset += numRead;         }        if(offset < bytes.length) {             thrownewIOException("Could not completely read file " + file.getName());         }        is.close();        returnbytes;     }

热点排行