Merge branch 'stable-7.2' into stable-7.3

* stable-7.2:
  Ensure pack files are closed after git.close()
  util.Iterators: suppress warning about object arrays
  util.Iterators: private constructor for utility class
  Prevent CommitGraphWriter.write() from closing its stream
  Make CancellableDigestOutputStream extend FilterOutputStream

Change-Id: Ifc76978d796c2dc196a2733e2cbbe0cd959cca24
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java
index 55539e2..45ca470 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java
@@ -134,8 +134,9 @@ public Stats write(@NonNull ProgressMonitor monitor,
 		chunks = Collections.unmodifiableList(chunks);
 
 		long expectedSize = calculateExpectedSize(chunks);
-		try (CancellableDigestOutputStream out = new CancellableDigestOutputStream(
-				monitor, commitGraphStream)) {
+		try {
+			CancellableDigestOutputStream out = new CancellableDigestOutputStream(
+				monitor, commitGraphStream);
 			writeHeader(out, chunks.size());
 			writeChunkLookup(out, chunks);
 			writeChunks(out, chunks);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index c08a92e..6001a7a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -944,13 +944,9 @@ void writeCommitGraph(@NonNull Set<? extends ObjectId> wants)
 			tmpFile = File.createTempFile("commit_", //$NON-NLS-1$
 					COMMIT_GRAPH.getTmpExtension(),
 					repo.getObjectDatabase().getInfoDirectory());
-			// write the commit-graph file
-			try (FileOutputStream fos = new FileOutputStream(tmpFile);
-					FileChannel channel = fos.getChannel();
-					OutputStream channelStream = Channels
-							.newOutputStream(channel)) {
-				writer.write(pm, channelStream);
-				channel.force(true);
+			// write the commit-graph to temporary file
+			try (FileOutputStream fos = new FileOutputStream(tmpFile)) {
+				writer.write(pm, fos);
 			}
 
 			// rename the temporary file to real file
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java
index 15c125c..9c60d36 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java
@@ -522,7 +522,8 @@ else if (eb < 4)
 			bs = tableSize / 2;
 		}
 		removalBlockSize = bs;
-		numRemovalBlocks = tableSize / removalBlockSize;
+		numRemovalBlocks = (int) Math
+				.ceil((double) tableSize / removalBlockSize);
 		blockBeingRemoved = numRemovalBlocks - 1;
 
 		if (maxFiles < 1)
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/io/CancellableDigestOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/io/CancellableDigestOutputStream.java
index ce86eab..9ad2f43 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/io/CancellableDigestOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/io/CancellableDigestOutputStream.java
@@ -15,6 +15,7 @@
 
 import java.io.IOException;
 import java.io.InterruptedIOException;
+import java.io.FilterOutputStream;
 import java.io.OutputStream;
 import java.security.MessageDigest;
 
@@ -22,15 +23,13 @@
  * An OutputStream that keeps a digest and checks every N bytes for
  * cancellation.
  */
-public class CancellableDigestOutputStream extends OutputStream {
+public class CancellableDigestOutputStream extends FilterOutputStream {
 
 	/** The OutputStream checks every this value for cancellation **/
 	public static final int BYTES_TO_WRITE_BEFORE_CANCEL_CHECK = 128 * 1024;
 
 	private final ProgressMonitor writeMonitor;
 
-	private final OutputStream out;
-
 	private final MessageDigest md = Constants.newMessageDigest();
 
 	private long count;
@@ -47,8 +46,8 @@ public class CancellableDigestOutputStream extends OutputStream {
 	 */
 	public CancellableDigestOutputStream(ProgressMonitor writeMonitor,
 			OutputStream out) {
+		super(out);
 		this.writeMonitor = writeMonitor;
-		this.out = out;
 		this.checkCancelAt = BYTES_TO_WRITE_BEFORE_CANCEL_CHECK;
 	}
 
@@ -113,9 +112,4 @@ public final void write(byte[] b, int off, int len) throws IOException {
 			len -= n;
 		}
 	}
-
-	@Override
-	public void flush() throws IOException {
-		out.flush();
-	}
 }
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/Iterators.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/Iterators.java
index 74b728b..93a2847 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/Iterators.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/Iterators.java
@@ -24,6 +24,7 @@ public class Iterators {
 	 * @param array T[]
 	 * @return Iterator<T>
 	 */
+	@SuppressWarnings("AvoidObjectArrays")
 	public static <T> Iterator<T> reverseIterator(T[] array) {
 		return new Iterator<>() {
 			int index = array.length;
@@ -54,4 +55,7 @@ public Iterator<T> iterator() {
 			}
 		};
 	}
+
+	private Iterators() {
+	}
 }