The getContents method of MockOutputStream is taking
the bytes that have been written and converting that
to a string using the platform default encoding. This
is the only way to access what has been written.
This is plain wrong. It should be returning the
contents as a byte array. The data written may be
binary data, not textual data. The conversion to a
String will differ from one platform as you are using
the platform default encoding. On Windows the
conversion from bytes to String is not even lossless.
There are certain characters in the range 0x80 to 0x9F
do not exist in the platform and will get mapped to
\uFFFD. None of the bytes in that range gets mapped to
the a character of the same value.
A method to get the data as a byte array needs to be
provided either instead of or in addition to a method
to get it as text. If you provide a means to get it as
text it should be overloaded to also accept an
encoding parameter. But the string methods are really
unnecessary as you can create a String from the byte
Log in to post a comment.