This is the problem:
while ((b = stream.read()) != -1) {
stringBuilder.append((char) b);
}
That's effectively using ISO-8859-1.
Instead, you should create an InputStreamReader
from the InputStream
, specifying UTF-8 as the encoding (as that's what you say you accept), and then read from that. You could read from it directly, or use something like Guava and CharStreams.toString
:
InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
String text = CharStreams.toString(reader);