Skip to content

Commit d748e99

Browse files
committed
fix: move back positivity check to helper method
1 parent 0f857f8 commit d748e99

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/main/java/org/apache/commons/io/IOUtils.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,13 +2684,8 @@ public static byte[] toByteArray(final InputStream inputStream) throws IOExcepti
26842684
* @throws NullPointerException if {@code input} is {@code null}.
26852685
* @since 2.1
26862686
*/
2687-
@SuppressWarnings("resource")
26882687
public static byte[] toByteArray(final InputStream input, final int size) throws IOException {
2689-
Objects.requireNonNull(input, "input");
2690-
if (size < 0) {
2691-
throw new IllegalArgumentException("Size must be equal or greater than zero: " + size);
2692-
}
2693-
return toByteArray(input::read, size);
2688+
return toByteArray(Objects.requireNonNull(input, "input")::read, size);
26942689
}
26952690

26962691
/**
@@ -2790,6 +2785,9 @@ public static byte[] toByteArray(final InputStream input, final int size, final
27902785
* @throws IllegalArgumentException if {@code size} is less than zero.
27912786
*/
27922787
static byte[] toByteArray(final IOTriFunction<byte[], Integer, Integer, Integer> input, final int size) throws IOException {
2788+
if (size < 0) {
2789+
throw new IllegalArgumentException("Size must be equal or greater than zero: " + size);
2790+
}
27932791
if (size == 0) {
27942792
return EMPTY_BYTE_ARRAY;
27952793
}

src/main/java/org/apache/commons/io/RandomAccessFiles.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ private static long length(final RandomAccessFile raf) throws IOException {
7676
* other I/O error occurs.
7777
*/
7878
public static byte[] read(final RandomAccessFile input, final long position, final int length) throws IOException {
79-
Objects.requireNonNull(input, "input");
8079
input.seek(position);
81-
if (length < 0) {
82-
throw new IllegalArgumentException("Size must be equal or greater than zero: " + length);
83-
}
8480
return IOUtils.toByteArray(input::read, length);
8581
}
8682

0 commit comments

Comments
 (0)