Some fixes on attachment writer:

* Flush and close base64 output stream
  This was previously causing a bug where the last byte wasn't always written

* More stringent check on TestUtils.streamsEqual()
  It wasn't failing when the second stream was longer

* Early exit on MultiPartAttachmentWriter.read()
  No point continuing when there are no more bytes left