diff options
author | Shawn Pearce <spearce@spearce.org> | 2016-11-13 11:24:41 -0800 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2016-11-14 15:33:54 -0800 |
commit | 8208da2f59ca13d93bd396e2f8189b0fefdb764d (patch) | |
tree | f9dad738be25b1d733e30010665264e22bf3b803 /org.eclipse.jgit.test | |
parent | 3e522526229ed304aa603ed5a38298971ceea464 (diff) | |
download | jgit-8208da2f59ca13d93bd396e2f8189b0fefdb764d.tar.gz jgit-8208da2f59ca13d93bd396e2f8189b0fefdb764d.zip |
Deprecate SafeBufferedOutputStream
Java 8 fixed the silent flush during close issue by
FilterOutputStream (base class of BufferedOutputStream)
using try-with-resources to close the stream, getting a
behavior matching what JGit's SafeBufferedOutputStream
was doing:
try {
flush();
} finally {
out.close();
}
With Java 8 as the minimum required version to run JGit
it is no longer necessary to override close() or have
this class. Deprecate the class, and use the JRE's version
of close.
Change-Id: Ic0584c140010278dbe4062df2e71be5df9a797b3
Diffstat (limited to 'org.eclipse.jgit.test')
3 files changed, 13 insertions, 21 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java index 638a163757..b4234dcba3 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java @@ -45,6 +45,7 @@ package org.eclipse.jgit.diff; import static org.junit.Assert.assertEquals; +import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -65,7 +66,6 @@ import org.eclipse.jgit.treewalk.filter.PathFilter; import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.io.DisabledOutputStream; -import org.eclipse.jgit.util.io.SafeBufferedOutputStream; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -381,7 +381,7 @@ public class DiffFormatterTest extends RepositoryTestCase { write(new File(folder, "folder.txt"), "folder"); try (Git git = new Git(db); ByteArrayOutputStream os = new ByteArrayOutputStream(); - DiffFormatter dfmt = new DiffFormatter(new SafeBufferedOutputStream(os))) { + DiffFormatter dfmt = new DiffFormatter(new BufferedOutputStream(os))) { git.add().addFilepattern(".").call(); git.commit().setMessage("Initial commit").call(); write(new File(folder, "folder.txt"), "folder change"); @@ -414,7 +414,7 @@ public class DiffFormatterTest extends RepositoryTestCase { write(new File(folder, "folder.txt"), "folder"); try (Git git = new Git(db); ByteArrayOutputStream os = new ByteArrayOutputStream(); - DiffFormatter dfmt = new DiffFormatter(new SafeBufferedOutputStream(os))) { + DiffFormatter dfmt = new DiffFormatter(new BufferedOutputStream(os))) { git.add().addFilepattern(".").call(); RevCommit commit = git.commit().setMessage("Initial commit").call(); write(new File(folder, "folder.txt"), "folder change"); @@ -446,7 +446,7 @@ public class DiffFormatterTest extends RepositoryTestCase { write(new File(folder, "folder.txt"), "folder"); try (Git git = new Git(db); ByteArrayOutputStream os = new ByteArrayOutputStream(); - DiffFormatter dfmt = new DiffFormatter(new SafeBufferedOutputStream(os));) { + DiffFormatter dfmt = new DiffFormatter(new BufferedOutputStream(os));) { git.add().addFilepattern(".").call(); RevCommit commit = git.commit().setMessage("Initial commit").call(); write(new File(folder, "folder.txt"), "folder change"); @@ -473,7 +473,7 @@ public class DiffFormatterTest extends RepositoryTestCase { @Test public void testDiffNullToNull() throws Exception { try (ByteArrayOutputStream os = new ByteArrayOutputStream(); - DiffFormatter dfmt = new DiffFormatter(new SafeBufferedOutputStream(os))) { + DiffFormatter dfmt = new DiffFormatter(new BufferedOutputStream(os))) { dfmt.setRepository(db); dfmt.format((AnyObjectId) null, null); dfmt.flush(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java index 56d2d5b22f..ece8f67368 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/AbbreviationTest.java @@ -50,6 +50,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -69,7 +70,6 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevBlob; import org.eclipse.jgit.transport.PackedObjectInfo; import org.eclipse.jgit.util.FileUtils; -import org.eclipse.jgit.util.io.SafeBufferedOutputStream; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -180,13 +180,10 @@ public class AbbreviationTest extends LocalDiskRepositoryTestCase { File idxFile = new File(packDir, packName + ".idx"); File packFile = new File(packDir, packName + ".pack"); FileUtils.mkdir(packDir, true); - OutputStream dst = new SafeBufferedOutputStream(new FileOutputStream( - idxFile)); - try { + try (OutputStream dst = new BufferedOutputStream( + new FileOutputStream(idxFile))) { PackIndexWriter writer = new PackIndexWriterV2(dst); writer.write(objects, new byte[OBJECT_ID_LENGTH]); - } finally { - dst.close(); } new FileOutputStream(packFile).close(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java index 9d7a4822a3..1d71cb3cff 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ConcurrentRepackTest.java @@ -51,6 +51,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.fail; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -71,7 +72,6 @@ import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.file.WindowCacheConfig; import org.eclipse.jgit.util.FileUtils; -import org.eclipse.jgit.util.io.SafeBufferedOutputStream; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -235,20 +235,15 @@ public class ConcurrentRepackTest extends RepositoryTestCase { throws IOException { final long begin = files[0].getParentFile().lastModified(); NullProgressMonitor m = NullProgressMonitor.INSTANCE; - OutputStream out; - out = new SafeBufferedOutputStream(new FileOutputStream(files[0])); - try { + try (OutputStream out = new BufferedOutputStream( + new FileOutputStream(files[0]))) { pw.writePack(m, m, out); - } finally { - out.close(); } - out = new SafeBufferedOutputStream(new FileOutputStream(files[1])); - try { + try (OutputStream out = new BufferedOutputStream( + new FileOutputStream(files[1]))) { pw.writeIndex(out); - } finally { - out.close(); } touch(begin, files[0].getParentFile()); |