hello,I am Tester using InstrumetationTestCase to Test, and i want to write 
some case about file transfer,However,when run,logcat display  some abnormal
below is my code,debug process,  the defect pointer is ""
  while(bis.read() != -1)
{ 
if(bis.read(mybytearray) == -1) break;

for(int i = 0 ; i < mybytearray.length ; i++)
{ 
Log.e("####weixiang --!!!","start Write");
outStream.write(mybytearray[i]);
} 

}
but I don't know how to fixed it~
 
***********************************************************************************************************
public void testBTFileTransfer() throws Exception {
    BluetoothDevice 
remotebtdevice=mybluetooth.getRemoteDevice(searchBtDeviceMAC_pcsuit);
    String sdcard=Environment.getExternalStorageDirectory()+"/";
    //String filepath= sdcard + "Wifi_Module_Test/"+"1.mp3";
    String filepath= sdcard + "Wifi_Module_Test/"+"1.mp3";
    Log.e("##### weixiang Tag ###", filepath);
    if(remotebtdevice.getBondState() != BluetoothDevice.BOND_BONDED)
    {
        testBTPairresult_accept();
    }
      new FileTransferThread(remotebtdevice).start();
    sleep(300*1000);  
}
private class FileTransferThread extends Thread
{
    private final BluetoothDevice mydevice;
    private final BluetoothSocket mysocket;
    //static final String SPP_UUID = "00001106-0000-1000-8000-00805F9B34FB";
    static final String SPP_UUID ="00001105-0000-1000-8000-00805f9b34fb";
    
    //private final OutputStream outStream;
    private final UUID uuid;
    private  InputStream mmInStream;   
    private  OutputStream mmOutStream;
    public FileTransferThread(BluetoothDevice device) throws IOException{
        mydevice=device;
        BluetoothSocket temsocket=null;
        uuid= UUID.fromString(SPP_UUID);
        //InputStream tmpIn = null;        
        //OutputStream tmpOut = null;
    try{
        
        temsocket=device.createRfcommSocketToServiceRecord(uuid);
            
    }catch (IOException e){}
        mysocket=temsocket;
        }
        
    
    public void run()
    {
        
        // add new socket Access
        try {
            mysocket.connect();
        } catch (IOException connectException) {
            
            try{
                mysocket.close();
            } catch(IOException closeException) {}
            // TODO Auto-generated catch block
        }
        
     //below is for Read/Write stream
     File myfile=new File(filepath);
     byte[] mybytearray = new byte[(int)myfile.length()];     
     Log.e("TAG","file length() =" + (int)myfile.length());    
     OutputStream outStream = null;
     FileInputStream fis = null;
     
     
     //init outputstream
     try{
         outStream =mysocket.getOutputStream();
         Log.e("tag1", "outputstream create success");
     }catch (IOException e)
     {
         Log.e("tag1", "ON RESUME: Output stream creation failed.");    
     }
     
     //init inputstream
    try {
        fis = new FileInputStream(myfile);
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }   
    
    
     Log.e("TAG","fis created");    
     
     BufferedInputStream bis = new BufferedInputStream(fis,4*1024 );     
     Log.e("TAG","bis created success");     
     
     /*
     try {
        bis.read(mybytearray,0,mybytearray.length);
        
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    */
    
    
     
     try {
        
         
         while(bis.read() != -1)
         {  
             if(bis.read(mybytearray) == -1) break;
             
             for(int i = 0 ; i < mybytearray.length ; i++)
             {    
                 Log.e("####weixiang   --!!!","start Write");
                 outStream.write(mybytearray[i]);
             } 
             
         }
         //Log.e("####weixiang   --!!!","read over!!!");
        
         /*
         while(bis.read()!= -1)
         {
             outStream.write(mybytearray, 0, mybytearray.length);
             Log.e("####weixiang   --!!!","start Write");
         }
         /*
         for(int i = 0 ; i < mybytearray.length ; i++){     } 
         */
         
         
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     
     Log.d("TAG","BYTES WRITTEN to OUTSTREAM of socket");       
     try {
        outStream.flush();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }     Log.d("TAG","bytes flushed");     
     try {
        outStream.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     try {
        mysocket.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     Log.d("TAG","socket closed");  
     
         
    } 
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to