skipIntervalSize - 1. Writes are already buffered in BufferedOutputStream. I agree that the recursive function is a little overkill instead of a for loop...