in src/main/java/com/amazonaws/kinesisvideo/encoding/ChunkDecoder.java [177:216]
public static Integer parseResponseBodyAndDecodeAck(final BufferedReader reader,
final Consumer<String> ackTimestampConsumer) {
String line;
int chunkSize;
int numBytesRead, offset, ackCount = 0;
try {
line = skipEmptyLines(reader);
// Parse chunk data
LOG.debug("Chunk size: " + line);
do {
chunkSize = Integer.parseInt(line.trim(), HEX_RADIX);
if (chunkSize == 0) {
break;
}
final char[] buff = new char[MAX_BUFFER_BYTES];
offset = 0;
do {
numBytesRead = reader.read(buff, offset, chunkSize + 2 - offset);
if (numBytesRead < 0) {
throw new RuntimeException("Unexpected end of stream while reading chunked data");
}
offset += numBytesRead;
} while (offset < chunkSize + 2);
// send the ack string to ack consumer with the exact number of bytes
final String chunk = new String(buff, 0, chunkSize);
LOG.debug("Chunk: " + chunk);
ackTimestampConsumer.accept(chunk);
line = reader.readLine();
LOG.debug("Chunk size: " + line);
} while (line != null);
} catch (final Throwable e) {
throw new RuntimeException("Exception while decoding Ack in response ! ", e);
}
return ackCount;
}