Skip to content

Commit 4ff1624

Browse files
yinhewboltomli
authored andcommitted
When the response lenght is long, it will be chunked to multiple parts, and need multiple times of read to receive the whole stream
1 parent ddaa55d commit 4ff1624

File tree

1 file changed

+8
-1
lines changed
  • PronunciationAssessment/Java/jre/src/com/microsoft/cognitiveservices/pronunciationassessment

1 file changed

+8
-1
lines changed

PronunciationAssessment/Java/jre/src/com/microsoft/cognitiveservices/pronunciationassessment/Sample.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,14 @@ public static void main(String[] args) throws Exception {
9393
// receive response
9494
byte[] responseBuffer = new byte[connection.getContentLength()];
9595
InputStream inputStream = connection.getInputStream();
96-
inputStream.read(responseBuffer);
96+
int offset = 0;
97+
int readBytes = inputStream.read(responseBuffer);
98+
while (readBytes != -1)
99+
{
100+
offset += readBytes;
101+
readBytes = inputStream.read(responseBuffer, offset, responseBuffer.length - offset);
102+
}
103+
97104
String result = new String(responseBuffer, "utf-8"); // the result is a JSON, you can parse it with a JSON library
98105

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

0 commit comments

Comments
 (0)