Having a java.awt.image.BufferedImage
I'm getting and returning a ByteArrayOutputStream
by:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( combined, "png", baos );
return baos;
Then I generate a base64 representation to be returned on a REST endpoint:
return new String(Base64.encodeBase64(baos.toByteArray()), Charset.forName("UTF-8"));
My question is: should I flush and close the baos?
(I've never understood properly when I should close a baos and when not, so any tip will be appreciated)