From 90f984c71f719310153a9f42bc35a2b9ca81f131 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 14 Jun 2012 12:49:57 -0700 Subject: [PATCH] Define ObjectInserter.Filter to wrap another ObjectInserter Filter supports wrapping another ObjectInserter. By default all methods are delegated to the wrapped inserter. Implementors may override methods selectively for altered behavior. The instance that is wrapped may be determined dynamically by code, supporting lazy allocation of the delegate, or other patterns like object pooling. Change-Id: I7b2613d09e73f94e675bad33afbb693f6a7f3df6 --- .../org/eclipse/jgit/lib/ObjectInserter.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java index 69b1e237e..0bed0dd9e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java @@ -91,6 +91,60 @@ public abstract class ObjectInserter { } } + /** Wraps a delegate ObjectInserter. */ + public static abstract class Filter extends ObjectInserter { + /** @return delegate ObjectInserter to handle all processing. */ + protected abstract ObjectInserter delegate(); + + @Override + protected byte[] buffer() { + return delegate().buffer(); + } + + public ObjectId idFor(int type, byte[] data) { + return delegate().idFor(type, data); + } + + public ObjectId idFor(int type, byte[] data, int off, int len) { + return delegate().idFor(type, data, off, len); + } + + public ObjectId idFor(int objectType, long length, InputStream in) + throws IOException { + return delegate().idFor(objectType, length, in); + } + + public ObjectId idFor(TreeFormatter formatter) { + return delegate().idFor(formatter); + } + + public ObjectId insert(int type, byte[] data) throws IOException { + return delegate().insert(type, data); + } + + public ObjectId insert(int type, byte[] data, int off, int len) + throws IOException { + return delegate().insert(type, data, off, len); + } + + public ObjectId insert(int objectType, long length, InputStream in) + throws IOException { + return delegate().insert(objectType, length, in); + } + + public PackParser newPackParser(InputStream in) throws IOException { + return delegate().newPackParser(in); + } + + public void flush() throws IOException { + delegate().flush(); + } + + public void release() { + delegate().release(); + } + } + /** Digest to compute the name of an object. */ private final MessageDigest digest;