private void writeTo(Writer out, String encoding) throws IOException{
//Get the charset based on the encoding or return the default if
//encoding == null
Charset charset = (encoding == null) ?
Charset.defaultCharset() : Charset.forName(encoding);
CharsetDecoder decoder = charset.newDecoder();
CharBuffer decodedBuffer = decoder.decode(
ByteBuffer.wrap(_byteArrayOutputStream.getInnerArray(),
0,_byteArrayOutputStream.getInnerCount()));
if (decodedBuffer.hasArray()){
out.write(decodedBuffer.array());