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. 16
      org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java

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

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

Loading…
Cancel
Save