Browse Source

TransportHttp: Refactor to use try-with-resource and suppress resource warning

Change-Id: I130269e7c5e46aea2152dea6b02539529208eea2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.0
David Pursehouse 7 years ago
parent
commit
0bc2020412
  1. 25
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java

25
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java

@ -336,15 +336,9 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
useSmartHttp = on;
}
/** {@inheritDoc} */
@Override
public FetchConnection openFetch() throws TransportException,
NotSupportedException {
final String service = SVC_UPLOAD_PACK;
try {
final HttpConnection c = connect(service);
final InputStream in = openInputStream(c);
try {
@SuppressWarnings("resource") // Closed by caller
private FetchConnection getConnection(HttpConnection c, InputStream in,
String service) throws IOException {
BaseConnection f;
if (isSmartHttp(c, service)) {
readSmartHeaders(in, service);
@ -356,8 +350,17 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
}
f.setPeerUserAgent(c.getHeaderField(HttpSupport.HDR_SERVER));
return (FetchConnection) f;
} finally {
in.close();
}
/** {@inheritDoc} */
@Override
public FetchConnection openFetch() throws TransportException,
NotSupportedException {
final String service = SVC_UPLOAD_PACK;
try {
final HttpConnection c = connect(service);
try (InputStream in = openInputStream(c)) {
return getConnection(c, in, service);
}
} catch (NotSupportedException err) {
throw err;

Loading…
Cancel
Save