aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-03-05 16:28:59 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2018-03-05 16:28:59 +0900
commit4c2f613a5a5d4beb39a28ef9ff88bb85cd049d53 (patch)
tree771b01ca4b3ab733f4b7438cd64977627b8fb530 /org.eclipse.jgit/src/org
parent88151ed6208db74ac32e3e23a6288565bedbfe9c (diff)
downloadjgit-4c2f613a5a5d4beb39a28ef9ff88bb85cd049d53.tar.gz
jgit-4c2f613a5a5d4beb39a28ef9ff88bb85cd049d53.zip
TransportHttp: Open auto-closeable resources in try-with-resource
Change-Id: I2f713b79ff07f5759c189f384cd25adb9b9f5761 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit/src/org')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java43
1 files changed, 14 insertions, 29 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 db43edc4ca..a1826231ab 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
@@ -371,12 +371,9 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
private WalkFetchConnection newDumbConnection(InputStream in)
throws IOException, PackProtocolException {
HttpObjectDB d = new HttpObjectDB(objectsUrl);
- BufferedReader br = toBufferedReader(in);
Map<String, Ref> refs;
- try {
+ try (BufferedReader br = toBufferedReader(in)) {
refs = d.readAdvertisedImpl(br);
- } finally {
- br.close();
}
if (!refs.containsKey(HEAD)) {
@@ -391,8 +388,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
int status = HttpSupport.response(conn);
switch (status) {
case HttpConnection.HTTP_OK: {
- br = toBufferedReader(openInputStream(conn));
- try {
+ try (BufferedReader br = toBufferedReader(
+ openInputStream(conn))) {
String line = br.readLine();
if (line != null && line.startsWith(RefDirectory.SYMREF)) {
String target = line.substring(RefDirectory.SYMREF.length());
@@ -406,8 +403,6 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
HEAD, ObjectId.fromString(line));
refs.put(r.getName(), r);
}
- } finally {
- br.close();
}
break;
}
@@ -438,8 +433,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
final String service = SVC_RECEIVE_PACK;
try {
final HttpConnection c = connect(service);
- final InputStream in = openInputStream(c);
- try {
+ try (InputStream in = openInputStream(c)) {
if (isSmartHttp(c, service)) {
return smartPush(service, c, in);
} else if (!useSmartHttp) {
@@ -450,8 +444,6 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
final String msg = JGitText.get().remoteDoesNotSupportSmartHTTPPush;
throw new NotSupportedException(msg);
}
- } finally {
- in.close();
}
} catch (NotSupportedException err) {
throw err;
@@ -966,21 +958,16 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
@Override
Collection<String> getPackNames() throws IOException {
final Collection<String> packs = new ArrayList<>();
- try {
- final BufferedReader br = openReader(INFO_PACKS);
- try {
- for (;;) {
- final String s = br.readLine();
- if (s == null || s.length() == 0)
- break;
- if (!s.startsWith("P pack-") || !s.endsWith(".pack")) //$NON-NLS-1$ //$NON-NLS-2$
- throw invalidAdvertisement(s);
- packs.add(s.substring(2));
- }
- return packs;
- } finally {
- br.close();
+ try (BufferedReader br = openReader(INFO_PACKS)) {
+ for (;;) {
+ final String s = br.readLine();
+ if (s == null || s.length() == 0)
+ break;
+ if (!s.startsWith("P pack-") || !s.endsWith(".pack")) //$NON-NLS-1$ //$NON-NLS-2$
+ throw invalidAdvertisement(s);
+ packs.add(s.substring(2));
}
+ return packs;
} catch (FileNotFoundException err) {
return packs;
}
@@ -1165,10 +1152,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
// Try to compress the content, but only if that is smaller.
TemporaryBuffer buf = new TemporaryBuffer.Heap(
http.getPostBuffer());
- try {
- GZIPOutputStream gzip = new GZIPOutputStream(buf);
+ try (GZIPOutputStream gzip = new GZIPOutputStream(buf)) {
out.writeTo(gzip, null);
- gzip.close();
if (out.length() < buf.length())
buf = out;
} catch (IOException err) {