package blue.mesh;

import android.util.Log;

public class ReadWriteThread extends Thread {

    private final RouterObject    router;
    private final Connection      connection;
    private static final String   TAG = "ReadWriteThread";

    protected ReadWriteThread(RouterObject a_router, Connection a_connection){
        Log.d(TAG, "RWTHREAD CONNECTED!");

        router = a_router;
        connection = a_connection;
    }

    public void run() {
        byte[] buffer = null;

        // Keep listening to the InputStream while connected
        while (true) {

            if (this.isInterrupted()) {
                break;
            }

            int bytes = connection.read( buffer );
            if( bytes > 0 ){
                router.route(buffer, Constants.SRC_OTHER);
            }
        }

        disconnect();

        return;
    }
    
    private int disconnect(){
        // On exit close the in and out sockets and the Bluetooth socket
        router.notifyDisconnected(connection.getID(), this);
        connection.close();
        
        Log.d(TAG, "ReadWriteThread returned");
        return Constants.SUCCESS;
    }

    protected int write(byte[] buffer) {
        Log.d(TAG, "Writing bytes");
        connection.write( buffer );
        return Constants.SUCCESS;
    }

}

@@ -479,11 +479,42 @@
  = n
-ull
+ew byte%5BConstants.MAX_MESSAGE_LEN%5D
 ;%0A%0A 
@@ -755,16 +755,341 @@
  %3E 0 )%7B%0A
+                Log.d(TAG, %22Got something%22);%0A            %7D%0A            if( bytes %3E 0 && buffer != null )%7B%0A                Log.d(TAG, buffer.toString());%0A                byte%5B%5D returnBuffer = new byte%5Bbytes%5D;%0A                for( int i = 0; i %3C bytes; i++ )%7B%0A                    returnBuffer%5Bi%5D = buffer%5Bi%5D;%0A                %7D%0A
         
@@ -1109,17 +1109,23 @@
 r.route(
-b
+returnB
 uffer, C
@@ -1584,17 +1584,40 @@
 ng bytes
-%22
+: %22 + buffer.toString() 
 );%0A     

Cut the message buffer down before forwarding