diff options
| author | Nick Pelly <npelly@google.com> | 2009-06-01 19:09:37 -0700 |
|---|---|---|
| committer | Nick Pelly <npelly@google.com> | 2009-06-02 12:35:48 -0700 |
| commit | 47e82dee6b18c33fab8c2cdf4f68b20d3663079e (patch) | |
| tree | 090df26f4dd1e404b43b13cda9f7663626706c82 /core/java/android/bluetooth/BluetoothOutputStream.java | |
| parent | 4599184a1c1c3f54b396c49b5728e4031e559e18 (diff) | |
Implement bulk read and writes for Bluetooth sockets.
Before: 0.1 kB/s
After: 100 kB/s
(in my java BT speed test app)
Diffstat (limited to 'core/java/android/bluetooth/BluetoothOutputStream.java')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothOutputStream.java | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/core/java/android/bluetooth/BluetoothOutputStream.java b/core/java/android/bluetooth/BluetoothOutputStream.java index 32e6d17c82a8..7e2ead478afb 100644 --- a/core/java/android/bluetooth/BluetoothOutputStream.java +++ b/core/java/android/bluetooth/BluetoothOutputStream.java @@ -24,7 +24,6 @@ import java.io.OutputStream; * * Used to read from a Bluetooth socket. * - * TODO: Implement bulk reads (instead of one byte at a time). * @hide */ /*package*/ final class BluetoothOutputStream extends OutputStream { @@ -52,6 +51,37 @@ import java.io.OutputStream; * @since Android 1.0 */ public void write(int oneByte) throws IOException { - mSocket.writeNative(oneByte); + byte b[] = new byte[1]; + b[0] = (byte)oneByte; + mSocket.writeNative(b, 0, 1); + } + + /** + * Writes {@code count} bytes from the byte array {@code buffer} starting + * at position {@code offset} to this stream. + * + * @param b + * the buffer to be written. + * @param offset + * the start position in {@code buffer} from where to get bytes. + * @param count + * the number of bytes from {@code buffer} to write to this + * stream. + * @throws IOException + * if an error occurs while writing to this stream. + * @throws IndexOutOfBoundsException + * if {@code offset < 0} or {@code count < 0}, or if + * {@code offset + count} is bigger than the length of + * {@code buffer}. + * @since Android 1.0 + */ + public void write(byte[] b, int offset, int count) throws IOException { + if (b == null) { + throw new NullPointerException("buffer is null"); + } + if ((offset | count) < 0 || count > b.length - offset) { + throw new IndexOutOfBoundsException("invalid offset or length"); + } + mSocket.writeNative(b, offset, count); } } |
