Details
Description
The OutputStream which StreamIoHandler provided doesn't perform defensive copy. Some wrapper OutputStreams and Writers (e.g. BufferedOutputStream and BufferedWriter) reuse their internal byte array, and causes the byte buffer to be modified before it's actually written out to the channel. There are two solutions:
1) Perform defensive copy in write(byte[], int, int):
public void write( byte[] b, int off, int len ) throws IOException
{ write( ByteBuffer.wrap( (byte[]) b.clone(), off, len ) ); }2) Wait for the WriteFuture for every operation.
The former sounds better IMO.