Browse Source

AmazonS3: ensure that errorStream is closed

Change-Id: I2abde5dbd4b785d70b7bc0b77188c0a075130eeb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.6
Matthias Sohn 8 years ago
parent
commit
cc0d58f9a0
  1. 32
      org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java

32
org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java

@ -529,21 +529,29 @@ public class AmazonS3 {
Integer.valueOf(HttpSupport.response(c)),
c.getResponseMessage()));
final InputStream errorStream = c.getErrorStream();
if (errorStream == null)
if (errorStream == null) {
return err;
}
final ByteArrayOutputStream b = new ByteArrayOutputStream();
byte[] buf = new byte[2048];
for (;;) {
final int n = errorStream.read(buf);
if (n < 0)
break;
if (n > 0)
b.write(buf, 0, n);
try {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
byte[] buf = new byte[2048];
for (;;) {
final int n = errorStream.read(buf);
if (n < 0) {
break;
}
if (n > 0) {
b.write(buf, 0, n);
}
}
buf = b.toByteArray();
if (buf.length > 0) {
err.initCause(new IOException("\n" + new String(buf))); //$NON-NLS-1$
}
} finally {
errorStream.close();
}
buf = b.toByteArray();
if (buf.length > 0)
err.initCause(new IOException("\n" + new String(buf))); //$NON-NLS-1$
return err;
}

Loading…
Cancel
Save