'Decode ByteArrayOutputStream without string it

I want a byteArray from a baos (ByteArrayOutputStream) but the baos contains some special characters (like '&' ) so I use StringEscapeUtils.unescapeHtml to decode it like below :

ByteArrayOutputStream baos
String baosString = StringEscapeUtils.unescapeHtml(baos.toString());
byte[] byteArray = baosString.getBytes(StandardCharsets.UTF_8)

That works when my baos is light but if my ByteArrayOutputStream is too big (and that the case in real conditions) I can't use the toString method because I have java heap space memory error, so I'm looking for some way to "unescape" or "decode" (or whatever you call it but need to replace the encoded characters) a ByteArrayOutputStream without stringify it. Is it possible ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source