Skip to content

Commit ad35207

Browse files
ctruedengab1one
authored andcommitted
DataHandle: add readFully(byte[], int, int) impl
1 parent 4839171 commit ad35207

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main/java/org/scijava/io/DataHandle.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import java.io.Closeable;
3535
import java.io.DataInput;
36+
import java.io.DataInputStream;
3637
import java.io.DataOutput;
3738
import java.io.EOFException;
3839
import java.io.IOException;
@@ -444,6 +445,20 @@ default void readFully(final byte[] b) throws IOException {
444445
readFully(b, 0, b.length);
445446
}
446447

448+
@Override
449+
default void readFully(final byte[] b, final int off, final int len)
450+
throws IOException
451+
{
452+
// NB: Adapted from java.io.DataInputStream.readFully(byte[], int, int).
453+
if (len < 0) throw new IndexOutOfBoundsException();
454+
int n = 0;
455+
while (n < len) {
456+
int count = read(b, off + n, len - n);
457+
if (count < 0) throw new EOFException();
458+
n += count;
459+
}
460+
}
461+
447462
@Override
448463
default int skipBytes(final int n) throws IOException {
449464
final int skip = (int) Math.min(n, length() - offset());

0 commit comments

Comments
 (0)