From 83555e7e303b45b9a96fbae4a7ebbff3cdb83b1c Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 26 Oct 2016 22:33:49 +0200 Subject: Use AtomicObjectOutputStream in CleanFilter Enhance and use AtomicObjectOutputStream to write temporary files in CleanFilter. Change-Id: I28987dad18255a9067344f94b4e836cbd183e4b1 Signed-off-by: Matthias Sohn --- .../lfs/internal/AtomicObjectOutputStream.java | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal') diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/AtomicObjectOutputStream.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/AtomicObjectOutputStream.java index 7e050b1e78..867cca5056 100644 --- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/AtomicObjectOutputStream.java +++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/AtomicObjectOutputStream.java @@ -48,6 +48,7 @@ import java.nio.file.Path; import java.security.DigestOutputStream; import java.text.MessageFormat; +import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.internal.storage.file.LockFile; import org.eclipse.jgit.lfs.errors.CorruptLongObjectException; import org.eclipse.jgit.lfs.lib.AnyLongObjectId; @@ -83,6 +84,22 @@ public class AtomicObjectOutputStream extends OutputStream { Constants.newMessageDigest()); } + /** + * @param path + * @throws IOException + */ + public AtomicObjectOutputStream(Path path) throws IOException { + this(path, null); + } + + /** + * @return content hash of the object which was streamed through this + * stream. May return {@code null} if called before closing this stream. + */ + public @Nullable AnyLongObjectId getId() { + return id; + } + @Override public void write(int b) throws IOException { out.write(b); @@ -102,7 +119,11 @@ public class AtomicObjectOutputStream extends OutputStream { public void close() throws IOException { out.close(); if (!aborted) { - verifyHash(); + if (id != null) { + verifyHash(); + } else { + id = LongObjectId.fromRaw(out.getMessageDigest().digest()); + } locked.commit(); } } -- cgit v1.2.3