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
This commit is contained in:
Shawn O. Pearce 2012-06-14 12:49:57 -07:00
parent d0e4943df1
commit 90f984c71f
1 changed files with 54 additions and 0 deletions

View File

@ -91,6 +91,60 @@ public void release() {
}
}
/** 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;