In an Android application I'm sending a picture taken from the Camera Intent
so I need to transform a Bitmap
to a byte array. To do this I use a ByteArrayOutputStream
as follow:
private byte[] getRawImageData(Bitmap source) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] rawImageData = null;
try {
source.compress(CompressFormat.JPEG, DEFAULT_COMRESSION, baos);
rawImageData = baos.toByteArray();
} finally {
try {
baos.close();
} catch (IOException e) {
// handle exception here
}
}
return rawImageData;
}
Everything works fine and all, the real question is the difference in the documentation of ByteArrayOutputStream
between the javadoc and the doc from Android.
The Javadoc reads
Closing a ByteArrayOutputStream has no effect.
the Android doc reads:
Closes this stream. This releases system resources used for this stream.
I am closing the stream not matter what but I would like to know which documentation is correct and why they are different.
close
is called? – Merlaclose
operation on a BAOS is a no-op. As has already been stated and you are currently doing, you should close it regardless. – Merla