Merge pull request #11779 from rajadilipkolli

* gh-11779:
  Use try-with-resources in HttpTunnelPayload

Closes gh-11779
pull/18281/head
Andy Wilkinson 5 years ago
commit bf56b24ca5

@ -84,11 +84,11 @@ public class HttpTunnelPayload {
headers.setContentLength(this.data.remaining());
headers.add(SEQ_HEADER, Long.toString(getSequence()));
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
WritableByteChannel body = Channels.newChannel(message.getBody());
try (WritableByteChannel body = Channels.newChannel(message.getBody())) {
while (this.data.hasRemaining()) {
body.write(this.data);
}
body.close();
}
}
/**
@ -117,15 +117,15 @@ public class HttpTunnelPayload {
}
String seqHeader = message.getHeaders().getFirst(SEQ_HEADER);
Assert.state(StringUtils.hasLength(seqHeader), "Missing sequence header");
ReadableByteChannel body = Channels.newChannel(message.getBody());
try (ReadableByteChannel body = Channels.newChannel(message.getBody())) {
ByteBuffer payload = ByteBuffer.allocate((int) length);
while (payload.hasRemaining()) {
body.read(payload);
}
body.close();
payload.flip();
return new HttpTunnelPayload(Long.valueOf(seqHeader), payload);
}
}
/**
* Return the payload data for the given source {@link ReadableByteChannel} or null if

Loading…
Cancel
Save