String valueString = new String(buffer, charset); byte[] formattedBuffer = String.format("%s", new Object[] { valueString }).getBytes(charset);