This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push: new 11edea6 Use Objects.requireNonNull() instead of custom check. Minor formatting. 11edea6 is described below commit 11edea657038529fea5e36f180f590bf20107cd1 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed Dec 25 20:01:08 2019 -0500 Use Objects.requireNonNull() instead of custom check. Minor formatting. --- .../archivers/examples/CloseableConsumerAdapter.java | 6 ++---- .../zip/ZipSplitReadOnlySeekableByteChannel.java | 10 ++++------ .../org/apache/commons/compress/changes/Change.java | 20 +++++++++----------- .../compressors/lz77support/LZ77Compressor.java | 10 ++++------ .../utils/ChecksumCalculatingInputStream.java | 14 +++++--------- 5 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/examples/CloseableConsumerAdapter.java b/src/main/java/org/apache/commons/compress/archivers/examples/CloseableConsumerAdapter.java index 2f2f7ab..a869420 100644 --- a/src/main/java/org/apache/commons/compress/archivers/examples/CloseableConsumerAdapter.java +++ b/src/main/java/org/apache/commons/compress/archivers/examples/CloseableConsumerAdapter.java @@ -20,16 +20,14 @@ package org.apache.commons.compress.archivers.examples; import java.io.Closeable; import java.io.IOException; +import java.util.Objects; final class CloseableConsumerAdapter implements Closeable { private final CloseableConsumer consumer; private Closeable closeable; CloseableConsumerAdapter(CloseableConsumer consumer) { - if (consumer == null) { - throw new NullPointerException("consumer must not be null"); - } - this.consumer = consumer; + this.consumer = Objects.requireNonNull(consumer, "consumer"); } <C extends Closeable> C track(C closeable) { diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitReadOnlySeekableByteChannel.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitReadOnlySeekableByteChannel.java index 4bb6bf3..1fa1019 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitReadOnlySeekableByteChannel.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitReadOnlySeekableByteChannel.java @@ -132,9 +132,8 @@ public class ZipSplitReadOnlySeekableByteChannel extends MultiReadOnlySeekableBy */ public static SeekableByteChannel forOrderedSeekableByteChannels(SeekableByteChannel lastSegmentChannel, Iterable<SeekableByteChannel> channels) throws IOException { - if (channels == null || lastSegmentChannel == null) { - throw new NullPointerException("channels must not be null"); - } + Objects.requireNonNull(channels, "channels"); + Objects.requireNonNull(lastSegmentChannel, "lastSegmentChannel"); List<SeekableByteChannel> channelsList = new ArrayList<>(); for (SeekableByteChannel channel : channels) { @@ -213,9 +212,8 @@ public class ZipSplitReadOnlySeekableByteChannel extends MultiReadOnlySeekableBy * @throws NullPointerException if files or lastSegmentFile is null */ public static SeekableByteChannel forFiles(File lastSegmentFile, Iterable<File> files) throws IOException { - if (files == null || lastSegmentFile == null) { - throw new NullPointerException("files must not be null"); - } + Objects.requireNonNull(files, "files"); + Objects.requireNonNull(lastSegmentFile, "lastSegmentFile"); List<File> filesList = new ArrayList<>(); for (File f : files) { diff --git a/src/main/java/org/apache/commons/compress/changes/Change.java b/src/main/java/org/apache/commons/compress/changes/Change.java index 27f293b..c2c60ed 100644 --- a/src/main/java/org/apache/commons/compress/changes/Change.java +++ b/src/main/java/org/apache/commons/compress/changes/Change.java @@ -19,6 +19,7 @@ package org.apache.commons.compress.changes; import java.io.InputStream; +import java.util.Objects; import org.apache.commons.compress.archivers.ArchiveEntry; @@ -47,9 +48,7 @@ class Change { * @param fileName the file name of the file to delete */ Change(final String fileName, final int type) { - if(fileName == null) { - throw new NullPointerException(); - } + Objects.requireNonNull(fileName, "fileName"); this.targetFile = fileName; this.type = type; this.input = null; @@ -60,15 +59,14 @@ class Change { /** * Construct a change which adds an entry. * - * @param pEntry the entry details - * @param pInput the InputStream for the entry data + * @param archiveEntry the entry details + * @param inputStream the InputStream for the entry data */ - Change(final ArchiveEntry pEntry, final InputStream pInput, final boolean replace) { - if(pEntry == null || pInput == null) { - throw new NullPointerException(); - } - this.entry = pEntry; - this.input = pInput; + Change(final ArchiveEntry archiveEntry, final InputStream inputStream, final boolean replace) { + Objects.requireNonNull(archiveEntry, "archiveEntry"); + Objects.requireNonNull(inputStream, "inputStream"); + this.entry = archiveEntry; + this.input = inputStream; type = TYPE_ADD; targetFile = null; this.replaceMode = replace; diff --git a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java index 7545e31..0f40135 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java +++ b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java @@ -20,6 +20,7 @@ package org.apache.commons.compress.compressors.lz77support; import java.io.IOException; import java.util.Arrays; +import java.util.Objects; /** * Helper class for compression algorithms that use the ideas of LZ77. @@ -255,12 +256,9 @@ public class LZ77Compressor { * @throws NullPointerException if either parameter is <code>null</code> */ public LZ77Compressor(Parameters params, Callback callback) { - if (params == null) { - throw new NullPointerException("params must not be null"); - } - if (callback == null) { - throw new NullPointerException("callback must not be null"); - } + Objects.requireNonNull(params, "params"); + Objects.requireNonNull(callback, "callback"); + this.params = params; this.callback = callback; diff --git a/src/main/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStream.java b/src/main/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStream.java index a722bea..e397ae2 100644 --- a/src/main/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStream.java +++ b/src/main/java/org/apache/commons/compress/utils/ChecksumCalculatingInputStream.java @@ -19,6 +19,7 @@ package org.apache.commons.compress.utils; import java.io.IOException; import java.io.InputStream; +import java.util.Objects; import java.util.zip.Checksum; /** @@ -30,18 +31,13 @@ public class ChecksumCalculatingInputStream extends InputStream { private final InputStream in; private final Checksum checksum; - public ChecksumCalculatingInputStream(final Checksum checksum, final InputStream in) { + public ChecksumCalculatingInputStream(final Checksum checksum, final InputStream inputStream) { - if ( checksum == null ){ - throw new NullPointerException("Parameter checksum must not be null"); - } - - if ( in == null ){ - throw new NullPointerException("Parameter in must not be null"); - } + Objects.requireNonNull(checksum, "checksum"); + Objects.requireNonNull(inputStream, "in"); this.checksum = checksum; - this.in = in; + this.in = inputStream; } /**