Writer writer = new BufferedWriter(new OutputStreamWriter(stream, CHARSET_UTF8));
Writer writer; try { writer = new BufferedWriter(new OutputStreamWriter(stream, "UTF8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); }
    private byte[] xmlToByteArray(Document doc) {        ByteArrayOutputStream stream = new ByteArrayOutputStream();        Writer writer = new BufferedWriter(new OutputStreamWriter(stream, CHARSET_UTF8));        try {            doc.write(writer);        } catch (IOException e) {            throw new RuntimeException(e);        } finally {            IOUtils.closeQuietly(writer);        }        return stream.toByteArray();    }