}
}
+ @Test
+ public void testConfigurableStreamFileThreshold() throws Exception {
+ byte[] data = getRng().nextBytes(300);
+ RevBlob id = tr.blob(data);
+ tr.branch("master").commit().add("A", id).create();
+ tr.packAndPrune();
+ assertTrue("has blob", wc.has(id));
+
+ ObjectLoader ol = wc.open(id);
+ ObjectStream in = ol.openStream();
+ assertTrue(in instanceof ObjectStream.SmallStream);
+ assertEquals(300, in.available());
+ in.close();
+
+ wc.setStreamFileThreshold(299);
+ ol = wc.open(id);
+ in = ol.openStream();
+ assertTrue(in instanceof ObjectStream.Filter);
+ assertEquals(1, in.available());
+ }
+
private static byte[] clone(int first, byte[] base) {
byte[] r = new byte[base.length];
System.arraycopy(base, 1, r, 1, r.length - 1);
DfsReader(DfsObjDatabase db) {
this.db = db;
+ this.streamFileThreshold = db.getReaderOptions().getStreamFileThreshold();
}
DfsReaderOptions getOptions() {
return baseCache;
}
- int getStreamFileThreshold() {
- return getOptions().getStreamFileThreshold();
- }
-
@Override
public ObjectReader newReader() {
return new DfsReader(db);
WindowCursor(FileObjectDatabase db) {
this.db = db;
this.createdFromInserter = null;
+ this.streamFileThreshold = WindowCache.getStreamFileThreshold();
}
WindowCursor(FileObjectDatabase db,
@Nullable ObjectDirectoryInserter createdFromInserter) {
this.db = db;
this.createdFromInserter = createdFromInserter;
+ this.streamFileThreshold = WindowCache.getStreamFileThreshold();
}
DeltaBaseCache getDeltaBaseCache() {
}
}
- int getStreamFileThreshold() {
- return WindowCache.getStreamFileThreshold();
- }
-
@Override
@Nullable
public ObjectInserter getCreatedFromInserter() {
/** Type hint indicating the caller doesn't know the type. */
public static final int OBJ_ANY = -1;
+ /**
+ * The threshold at which a file will be streamed rather than
+ * loaded entirely into memory.
+ */
+ protected int streamFileThreshold;
+
/**
* Construct a new reader from the same data.
* <p>
@Override
public abstract void close();
+ /**
+ * Sets the threshold at which a file will be streamed rather than loaded
+ * entirely into memory
+ *
+ * @param threshold
+ * the new threshold
+ * @since 4.6
+ */
+ public void setStreamFileThreshold(int threshold) {
+ streamFileThreshold = threshold;
+ }
+
+ /**
+ * Returns the threshold at which a file will be streamed rather than loaded
+ * entirely into memory
+ *
+ * @return the threshold in bytes
+ * @since 4.6
+ */
+ public int getStreamFileThreshold() {
+ return streamFileThreshold;
+ }
+
/**
* Wraps a delegate ObjectReader.
*