Browse Source

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
stable-2.1
Shawn O. Pearce 13 years ago
parent
commit
90f984c71f
  1. 54
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java

54
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;

Loading…
Cancel
Save