src/com/btwiz/library/BTSocket.java
public void readAsync(final byte[] buffer, final int offset, final int length, 
			final boolean readOnce, final IReadListener readListener) { 
		synchronized (readThreadLock) {
			if (readThread==null) {
				readThread = Executors.newSingleThreadExecutor();
				Log.e("BTSocket", "readThread created");
			}
		}		
		readThread.execute(new Runnable() {				
			@Override
			public void run() {
				int totalNumBytes = 0;
				for (;;) {
					try {
						int nBytes = read(buffer, offset, length);
						if (nBytes == -1) {
							throw new IOException("Read error: End of stream reached");
						}
						totalNumBytes += nBytes; 
						if (readOnce || totalNumBytes >= length) {
							if (readListener != null) {
								readListener.onSuccess(totalNumBytes);
							}
							return;
						}
						// else -- go on
					} 
					catch (IOException e) {
						e.printStackTrace();
						Log.e("BTSocket", "read error: " + e);
						if (readListener != null) {
							readListener.onError(totalNumBytes, e);
						}
						return;

					}
				}
			}
		});
	}
/**
	 * Perform an asynchronous read of buffer starting offset and and for <= length.  
	 * Raw read command will be called either once or in loop according to readOnce param.
	 * Upon readAsync complete/error the readListener will be activated 
	 */
Perform an asynchronous read of buffer starting offset and and for <= length.
Raw read command will be called either once or in loop according to readOnce param.
Upon readAsync complete/error the readListener will be activated
Perform an asynchronous read of buffer starting offset and and for < = length . Raw read command will be called either once or in loop according to readOnce param . Upon readAsync complete / error the readListener will be activated
public void readAsync(final byte[] buffer, final int offset, final int length, 
			final boolean readOnce, final IReadListener readListener) { 
		synchronized (readThreadLock) {
			if (readThread==null) {
				readThread = Executors.newSingleThreadExecutor();
				Log.e("BTSocket", "readThread created");
			}
		}		
		readThread.execute(new Runnable() {				
			@Override
			public void run() {
				int totalNumBytes = 0;
				for (;;) {
					try {
						int nBytes = read(buffer, offset, length);
						if (nBytes == -1) {
							throw new IOException("Read error: End of stream reached");
						}
						totalNumBytes += nBytes; 
						if (readOnce || totalNumBytes >= length) {
							if (readListener != null) {
								readListener.onSuccess(totalNumBytes);
							}
							return;
						}
					} 
					catch (IOException e) {
						e.printStackTrace();
						Log.e("BTSocket", "read error: " + e);
						if (readListener != null) {
							readListener.onError(totalNumBytes, e);
						}
						return;
					}
				}
			}
		});
	}
public void readAsync ( final byte [ ] buffer , final int offset , final int length , final boolean readOnce , final IReadListener readListener ) { synchronized ( readThreadLock ) { if ( readThread == null ) { readThread = Executors . newSingleThreadExecutor ( ) ; Log . e ( "BTSocket" , "readThread created" ) ; } } readThread . execute ( new Runnable ( ) { @ Override public void run ( ) { int totalNumBytes = 0 ; for ( ; ; ) { try { int nBytes = read ( buffer , offset , length ) ; if ( nBytes == - 1 ) { throw new IOException ( "Read error: End of stream reached" ) ; } totalNumBytes += nBytes ; if ( readOnce || totalNumBytes >= length ) { if ( readListener != null ) { readListener . onSuccess ( totalNumBytes ) ; } return ; } } catch ( IOException e ) { e . printStackTrace ( ) ; Log . e ( "BTSocket" , "read error: " + e ) ; if ( readListener != null ) { readListener . onError ( totalNumBytes , e ) ; } return ; } } } } ) ; }
Perform an asynchronous read of buffer starting offset and and for <= length.
Perform an asynchronous read of buffer starting offset and and for < = length .
// else -- go on