diff options
author | Anna Papitto <annapapitto@google.com> | 2022-12-02 15:56:56 -0800 |
---|---|---|
committer | Anna Papitto <annapapitto@google.com> | 2022-12-19 10:26:41 -0800 |
commit | 9b7c3ac11f968364799537040f4765b881ed96ae (patch) | |
tree | 8f8772b8da671f5b55aaa12700a7b6a52a271f72 /org.eclipse.jgit | |
parent | 0d10ebe5602bc31cd7176f0df8470b4ba6014d89 (diff) | |
download | jgit-9b7c3ac11f968364799537040f4765b881ed96ae.tar.gz jgit-9b7c3ac11f968364799537040f4765b881ed96ae.zip |
IO#readFully: provide overload that fills the full array
IO#readFully is often called with the intent to fill the destination
array from beginning to end. The redundant arguments for where to start
and stop filling are opportunities for bugs if specified incorrectly or
if not changed to match a changed array length.
Provide a overloaded method for filling the full destination array.
Change-Id: I964f18f4a061189cce1ca00ff0258669277ff499
Signed-off-by: Anna Papitto <annapapitto@google.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java index 6d5694e435..80877bbdc6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java @@ -207,6 +207,25 @@ public class IO { } /** + * Read from input until the entire byte array filled, or throw an exception + * if stream ends first. + * + * @param fd + * input stream to read the data from. + * @param dst + * buffer that must be fully populated + * @throws EOFException + * the stream ended before dst was fully populated. + * @throws java.io.IOException + * there was an error reading from the stream. + * @since 6.5 + */ + public static void readFully(InputStream fd, byte[] dst) + throws IOException { + readFully(fd, dst, 0, dst.length); + } + + /** * Read as much of the array as possible from a channel. * * @param channel |