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)), 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;
}
final ByteArrayOutputStream b = new ByteArrayOutputStream(); try {
byte[] buf = new byte[2048]; final ByteArrayOutputStream b = new ByteArrayOutputStream();
for (;;) { byte[] buf = new byte[2048];
final int n = errorStream.read(buf); for (;;) {
if (n < 0) final int n = errorStream.read(buf);
break; if (n < 0) {
if (n > 0) break;
b.write(buf, 0, n); }
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; return err;
} }

Loading…
Cancel
Save