diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2012-06-14 12:49:57 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2012-06-14 12:49:57 -0700 |
commit | 90f984c71f719310153a9f42bc35a2b9ca81f131 (patch) | |
tree | 75a725e70398a2a0b86dc60fe46cbf892fbff1e0 /org.eclipse.jgit | |
parent | d0e4943df1040add984c4fa0b32e791647946b2f (diff) | |
download | jgit-90f984c71f719310153a9f42bc35a2b9ca81f131.tar.gz jgit-90f984c71f719310153a9f42bc35a2b9ca81f131.zip |
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
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java | 54 |
1 files changed, 54 insertions, 0 deletions
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 69b1e237e4..0bed0dd9ed 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; |