summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-03-20 11:37:30 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-03-25 09:49:43 +0100
commit0bc2020412f36b2abf75e5aba1dd318443dbbb10 (patch)
tree2b6e58e4aa945ddc68a8f4bc2535582cf32885d1 /org.eclipse.jgit
parentd8234d310db7e730fba4e8685ac3bf8fb94046e8 (diff)
downloadjgit-0bc2020412f36b2abf75e5aba1dd318443dbbb10.tar.gz
jgit-0bc2020412f36b2abf75e5aba1dd318443dbbb10.zip
TransportHttp: Refactor to use try-with-resource and suppress resource warning
Change-Id: I130269e7c5e46aea2152dea6b02539529208eea2 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java33
1 files changed, 18 insertions, 15 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
index b300d55477..87c328f452 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
@@ -336,6 +336,22 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
useSmartHttp = on;
}
+ @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);
+ f = new SmartHttpFetchConnection(in);
+ } else {
+ // Assume this server doesn't support smart HTTP fetch
+ // and fall back on dumb object walking.
+ f = newDumbConnection(in);
+ }
+ f.setPeerUserAgent(c.getHeaderField(HttpSupport.HDR_SERVER));
+ return (FetchConnection) f;
+ }
+
/** {@inheritDoc} */
@Override
public FetchConnection openFetch() throws TransportException,
@@ -343,21 +359,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
final String service = SVC_UPLOAD_PACK;
try {
final HttpConnection c = connect(service);
- final InputStream in = openInputStream(c);
- try {
- BaseConnection f;
- if (isSmartHttp(c, service)) {
- readSmartHeaders(in, service);
- f = new SmartHttpFetchConnection(in);
- } else {
- // Assume this server doesn't support smart HTTP fetch
- // and fall back on dumb object walking.
- f = newDumbConnection(in);
- }
- f.setPeerUserAgent(c.getHeaderField(HttpSupport.HDR_SERVER));
- return (FetchConnection) f;
- } finally {
- in.close();
+ try (InputStream in = openInputStream(c)) {
+ return getConnection(c, in, service);
}
} catch (NotSupportedException err) {
throw err;