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());
while (this.data.hasRemaining()) {
body.write(this.data);
try (WritableByteChannel body = Channels.newChannel(message.getBody())) {
while (this.data.hasRemaining()) {
body.write(this.data);
}
}
body.close();
}
/**
@ -117,14 +117,14 @@ public class HttpTunnelPayload {
}
String seqHeader = message.getHeaders().getFirst(SEQ_HEADER);
Assert.state(StringUtils.hasLength(seqHeader), "Missing sequence header");
ReadableByteChannel body = Channels.newChannel(message.getBody());
ByteBuffer payload = ByteBuffer.allocate((int) length);
while (payload.hasRemaining()) {
body.read(payload);
try (ReadableByteChannel body = Channels.newChannel(message.getBody())) {
ByteBuffer payload = ByteBuffer.allocate((int) length);
while (payload.hasRemaining()) {
body.read(payload);
}
payload.flip();
return new HttpTunnelPayload(Long.valueOf(seqHeader), payload);
}
body.close();
payload.flip();
return new HttpTunnelPayload(Long.valueOf(seqHeader), payload);
}
/**

Loading…
Cancel
Save