Better names and in-line arg checking.
MODIFY
src/main/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStream.java
src/main/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStream.java
* @param data the buffer
*/
public UnsynchronizedByteArrayInputStream(final byte[] data) {
- Objects.requireNonNull(data);
- this.data = data;
+ this.data = Objects.requireNonNull(data);
this.offset = 0;
this.eod = data.length;
this.markedOffset = this.offset;
@@ -102,14 +101,13 @@ public UnsynchronizedByteArrayInputStream(final byte[] data, final int offset) {
* @throws IllegalArgumentException if the offset or length less than zero
*/
public UnsynchronizedByteArrayInputStream(final byte[] data, final int offset, final int length) {
- Objects.requireNonNull(data);
if (offset < 0) {
throw new IllegalArgumentException("offset cannot be negative");
}
if (length < 0) {
throw new IllegalArgumentException("length cannot be negative");
}
- this.data = data;
+ this.data = Objects.requireNonNull(data);
this.offset = min(offset, data.length > 0 ? data.length : offset);
this.eod = min(this.offset + length, data.length);
this.markedOffset = this.offset;
@@ -126,15 +124,15 @@ public int read() {
}
@Override
- public int read(final byte[] b) {
- Objects.requireNonNull(b);
- return read(b, 0, b.length);
+ public int read(final byte[] dest) {
+ Objects.requireNonNull(dest);
+ return read(dest, 0, dest.length);
}
@Override
- public int read(final byte[] b, final int off, final int len) {
- Objects.requireNonNull(b);
- if (off < 0 || len < 0 || off + len > b.length) {
+ public int read(final byte[] dest, final int off, final int len) {
+ Objects.requireNonNull(dest);
+ if (off < 0 || len < 0 || off + len > dest.length) {
throw new IndexOutOfBoundsException();
}
@@ -149,7 +147,7 @@ public int read(final byte[] b, final int off, final int len) {
if (actualLen <= 0) {
return 0;
}
- System.arraycopy(data, offset, b, off, actualLen);
+ System.arraycopy(data, offset, dest, off, actualLen);
offset += actualLen;
return actualLen;
}

Better names and in-line arg checking.