Skip to content

Commit

Permalink
When the response lenght is long, it will be chunked to multiple part…
Browse files Browse the repository at this point in the history
…s, and need multiple times of read to receive the whole stream
  • Loading branch information
yinhew authored and boltomli committed Aug 30, 2020
1 parent ddaa55d commit 4ff1624
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ public static void main(String[] args) throws Exception {
// receive response
byte[] responseBuffer = new byte[connection.getContentLength()];
InputStream inputStream = connection.getInputStream();
inputStream.read(responseBuffer);
int offset = 0;
int readBytes = inputStream.read(responseBuffer);
while (readBytes != -1)
{
offset += readBytes;
readBytes = inputStream.read(responseBuffer, offset, responseBuffer.length - offset);
}

String result = new String(responseBuffer, "utf-8"); // the result is a JSON, you can parse it with a JSON library

System.out.println("Pronunciation assessment result:\n");
Expand Down

0 comments on commit 4ff1624

Please sign in to comment.