import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Arrays;
import org.eclipse.jgit.junit.TestRng;
}
}
+ @Test
+ public void testInCoreInputStream() throws IOException {
+ final int cnt = 256;
+ final byte[] test = new TestRng(getName()).nextBytes(cnt);
+ final TemporaryBuffer.Heap b = new TemporaryBuffer.Heap(cnt + 4);
+ b.write(test);
+ b.close();
+
+ InputStream in = b.openInputStream();
+ byte[] act = new byte[cnt];
+ IO.readFully(in, act, 0, cnt);
+ assertTrue(Arrays.equals(test, act));
+ }
+
@Test
public void testInCoreLimit_SwitchOnAppendByte() throws IOException {
final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
long skipped = 0;
while (0 < cnt) {
int n = (int) Math.min(block.count - blockPos, cnt);
- if (n < 0) {
+ if (0 < n) {
blockPos += n;
skipped += n;
cnt -= n;
int copied = 0;
while (0 < len) {
int c = Math.min(block.count - blockPos, len);
- if (c < 0) {
+ if (0 < c) {
System.arraycopy(block.buffer, blockPos, b, off, c);
blockPos += c;
off += c;
len -= c;
+ copied += c;
} else if (nextBlock())
continue;
else