aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2016-11-13 11:24:41 -0800
committerDavid Pursehouse <david.pursehouse@gmail.com>2016-11-14 15:33:54 -0800
commit8208da2f59ca13d93bd396e2f8189b0fefdb764d (patch)
treef9dad738be25b1d733e30010665264e22bf3b803 /org.eclipse.jgit/src/org
parent3e522526229ed304aa603ed5a38298971ceea464 (diff)
downloadjgit-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/src/org')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriter.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java18
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/SafeBufferedOutputStream.java20
11 files changed, 27 insertions, 58 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
index b9101c028c..eeaab11afa 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
@@ -46,6 +46,7 @@
package org.eclipse.jgit.dircache;
import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
@@ -86,7 +87,6 @@ import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.MutableInteger;
import org.eclipse.jgit.util.NB;
import org.eclipse.jgit.util.TemporaryBuffer;
-import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
/**
* Support for the Git dircache (aka index file).
@@ -636,7 +636,7 @@ public class DirCache {
requireLocked(tmp);
try {
writeTo(liveFile.getParentFile(),
- new SafeBufferedOutputStream(tmp.getOutputStream()));
+ new BufferedOutputStream(tmp.getOutputStream()));
} catch (IOException err) {
tmp.unlock();
throw err;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java
index 39151a5d2f..f8f02e95e3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndexWriterV1.java
@@ -53,7 +53,6 @@ import java.text.MessageFormat;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.file.PackBitmapIndexBuilder.StoredEntry;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
import com.googlecode.javaewah.EWAHCompressedBitmap;
@@ -74,7 +73,7 @@ public class PackBitmapIndexWriterV1 {
*/
public PackBitmapIndexWriterV1(final OutputStream dst) {
out = new DigestOutputStream(dst instanceof BufferedOutputStream ? dst
- : new SafeBufferedOutputStream(dst),
+ : new BufferedOutputStream(dst),
Constants.newMessageDigest());
dataOutput = new SimpleDataOutput(out);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriter.java
index 6dfe74bf83..51539112e7 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriter.java
@@ -56,7 +56,6 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.transport.PackedObjectInfo;
import org.eclipse.jgit.util.NB;
-import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
/**
* Creates a table of contents to support random access by {@link PackFile}.
@@ -183,7 +182,7 @@ public abstract class PackIndexWriter {
*/
protected PackIndexWriter(final OutputStream dst) {
out = new DigestOutputStream(dst instanceof BufferedOutputStream ? dst
- : new SafeBufferedOutputStream(dst),
+ : new BufferedOutputStream(dst),
Constants.newMessageDigest());
tmp = new byte[4 + Constants.OBJECT_ID_LENGTH];
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java
index 4ebe5fedf3..75a3592213 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.lib;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -53,7 +54,6 @@ import java.util.List;
import org.eclipse.jgit.lib.RebaseTodoLine.Action;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
-import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
/**
* Offers methods to read and write files formatted like the git-rebase-todo
@@ -216,9 +216,8 @@ public class RebaseTodoFile {
*/
public void writeRebaseTodoFile(String path, List<RebaseTodoLine> steps,
boolean append) throws IOException {
- OutputStream fw = new SafeBufferedOutputStream(new FileOutputStream(
- new File(repo.getDirectory(), path), append));
- try {
+ try (OutputStream fw = new BufferedOutputStream(new FileOutputStream(
+ new File(repo.getDirectory(), path), append))) {
StringBuilder sb = new StringBuilder();
for (RebaseTodoLine step : steps) {
sb.setLength(0);
@@ -234,8 +233,6 @@ public class RebaseTodoFile {
sb.append('\n');
fw.write(Constants.encode(sb.toString()));
}
- } finally {
- fw.close();
}
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index 19d9610d0f..5179696417 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -52,6 +52,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.net.URISyntaxException;
import java.text.MessageFormat;
import java.util.Collection;
@@ -94,7 +95,6 @@ import org.eclipse.jgit.util.FileUtils;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.jgit.util.SystemReader;
-import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1799,15 +1799,12 @@ public abstract class Repository implements AutoCloseable {
throws FileNotFoundException, IOException {
File headsFile = new File(getDirectory(), filename);
if (heads != null) {
- BufferedOutputStream bos = new SafeBufferedOutputStream(
- new FileOutputStream(headsFile));
- try {
+ try (OutputStream bos = new BufferedOutputStream(
+ new FileOutputStream(headsFile))) {
for (ObjectId id : heads) {
id.copyTo(bos);
bos.write('\n');
}
- } finally {
- bos.close();
}
} else {
FileUtils.delete(headsFile, FileUtils.SKIP_MISSING);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java
index 22f343899d..23e3379f91 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java
@@ -44,6 +44,7 @@
package org.eclipse.jgit.transport;
import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -52,7 +53,6 @@ import java.net.Socket;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
-import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
/** Active network client of {@link Daemon}. */
public class DaemonClient {
@@ -95,7 +95,7 @@ public class DaemonClient {
void execute(final Socket sock) throws IOException,
ServiceNotEnabledException, ServiceNotAuthorizedException {
rawIn = new BufferedInputStream(sock.getInputStream());
- rawOut = new SafeBufferedOutputStream(sock.getOutputStream());
+ rawOut = new BufferedOutputStream(sock.getOutputStream());
if (0 < daemon.getTimeout())
sock.setSoTimeout(daemon.getTimeout() * 1000);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java
index a7f42fd873..c6e4c50801 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java
@@ -46,6 +46,7 @@
package org.eclipse.jgit.transport;
import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -62,7 +63,6 @@ import org.eclipse.jgit.errors.NotSupportedException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
/**
* Transport through a git-daemon waiting for anonymous TCP connections.
@@ -182,7 +182,7 @@ class TransportGitAnon extends TcpTransport implements PackTransport {
OutputStream sOut = sock.getOutputStream();
sIn = new BufferedInputStream(sIn);
- sOut = new SafeBufferedOutputStream(sOut);
+ sOut = new BufferedOutputStream(sOut);
init(sIn, sOut);
service("git-upload-pack", pckOut); //$NON-NLS-1$
@@ -221,7 +221,7 @@ class TransportGitAnon extends TcpTransport implements PackTransport {
OutputStream sOut = sock.getOutputStream();
sIn = new BufferedInputStream(sIn);
- sOut = new SafeBufferedOutputStream(sOut);
+ sOut = new BufferedOutputStream(sOut);
init(sIn, sOut);
service("git-receive-pack", pckOut); //$NON-NLS-1$
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java
index 292ba7ed8a..1528c71426 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java
@@ -48,6 +48,7 @@
package org.eclipse.jgit.transport;
import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -67,7 +68,6 @@ import org.eclipse.jgit.transport.resolver.ReceivePackFactory;
import org.eclipse.jgit.transport.resolver.UploadPackFactory;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.io.MessageWriter;
-import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
import org.eclipse.jgit.util.io.StreamCopyThread;
/**
@@ -258,7 +258,7 @@ class TransportLocal extends Transport implements PackTransport {
OutputStream upOut = uploadPack.getOutputStream();
upIn = new BufferedInputStream(upIn);
- upOut = new SafeBufferedOutputStream(upOut);
+ upOut = new BufferedOutputStream(upOut);
init(upIn, upOut);
readAdvertisedRefs();
@@ -311,7 +311,7 @@ class TransportLocal extends Transport implements PackTransport {
OutputStream rpOut = receivePack.getOutputStream();
rpIn = new BufferedInputStream(rpIn);
- rpOut = new SafeBufferedOutputStream(rpOut);
+ rpOut = new BufferedOutputStream(rpOut);
init(rpIn, rpOut);
readAdvertisedRefs();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java
index 4eaf3f9d8a..7b449c752a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java
@@ -45,6 +45,7 @@ package org.eclipse.jgit.transport;
import static org.eclipse.jgit.transport.WalkRemoteObjectDatabase.ROOT_DIR;
+import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -69,7 +70,6 @@ import org.eclipse.jgit.lib.Ref.Storage;
import org.eclipse.jgit.lib.RefWriter;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.RemoteRefUpdate.Status;
-import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
/**
* Generic push support for dumb transport protocols.
@@ -262,21 +262,15 @@ class WalkPushConnection extends BaseConnection implements PushConnection {
// Write the pack file, then the index, as readers look the
// other direction (index, then pack file).
//
- final String wt = "Put " + base.substring(0, 12); //$NON-NLS-1$
- OutputStream os = dest.writeFile(pathPack, monitor, wt + "..pack"); //$NON-NLS-1$
- try {
- os = new SafeBufferedOutputStream(os);
+ String wt = "Put " + base.substring(0, 12); //$NON-NLS-1$
+ try (OutputStream os = new BufferedOutputStream(
+ dest.writeFile(pathPack, monitor, wt + "..pack"))) { //$NON-NLS-1$
writer.writePack(monitor, monitor, os);
- } finally {
- os.close();
}
- os = dest.writeFile(pathIdx, monitor, wt + "..idx"); //$NON-NLS-1$
- try {
- os = new SafeBufferedOutputStream(os);
+ try (OutputStream os = new BufferedOutputStream(
+ dest.writeFile(pathIdx, monitor, wt + "..idx"))) { //$NON-NLS-1$
writer.writeIndex(os);
- } finally {
- os.close();
}
// Record the pack at the start of the pack info list. This
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java
index 3cd5929c7f..57bcfbd5e5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java
@@ -56,7 +56,6 @@ import java.util.ArrayList;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ProgressMonitor;
-import org.eclipse.jgit.util.io.SafeBufferedOutputStream;
/**
* A fully buffered output stream.
@@ -360,7 +359,7 @@ public abstract class TemporaryBuffer extends OutputStream {
overflow.write(b.buffer, 0, b.count);
blocks = null;
- overflow = new SafeBufferedOutputStream(overflow, Block.SZ);
+ overflow = new BufferedOutputStream(overflow, Block.SZ);
overflow.write(last.buffer, 0, last.count);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/SafeBufferedOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/SafeBufferedOutputStream.java
index 68f250da09..84c339889b 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/SafeBufferedOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/SafeBufferedOutputStream.java
@@ -43,20 +43,13 @@
package org.eclipse.jgit.util.io;
import java.io.BufferedOutputStream;
-import java.io.IOException;
import java.io.OutputStream;
/**
- * A BufferedOutputStream that throws an error if the final flush fails on
- * close.
- * <p>
- * Java's BufferedOutputStream swallows errors that occur when the output stream
- * tries to write the final bytes to the output during close. This may result in
- * corrupted files without notice.
- * </p>
+ * @deprecated use BufferedOutputStream in Java 8 and later.
*/
+@Deprecated
public class SafeBufferedOutputStream extends BufferedOutputStream {
-
/**
* @see BufferedOutputStream#BufferedOutputStream(OutputStream)
* @param out
@@ -76,13 +69,4 @@ public class SafeBufferedOutputStream extends BufferedOutputStream {
public SafeBufferedOutputStream(OutputStream out, int size) {
super(out, size);
}
-
- @Override
- public void close() throws IOException {
- try {
- flush();
- } finally {
- super.close();
- }
- }
}