garydgregory commented on code in PR #548:
URL: https://github.com/apache/commons-io/pull/548#discussion_r1439080863


##########
src/main/java/org/apache/commons/io/input/ChecksumInputStream.java:
##########
@@ -0,0 +1,208 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.commons.io.input;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.CheckedInputStream;
+import java.util.zip.Checksum;
+
+import org.apache.commons.io.build.AbstractStreamBuilder;
+
+/**
+ * Automatically verifies a {@link Checksum} value once the stream is 
exhausted.
+ * <p>
+ * If the {@link Checksum} does not meet the expected value when exhausted, 
then the input stream throws a
+ * {@link IOException}.
+ * </p>
+ * <p>
+ * If you do not need the verification or threshold feature, then use a plain 
{@link CheckedInputStream}.
+ * </p>
+ *
+ * @since 2.16.0
+ */
+public final class ChecksumInputStream extends CountingInputStream {
+
+    // @formatter:off
+    /**
+     * Builds a new {@link ChecksumInputStream} instance.
+     * <p>
+     * There is no default {@link Checksum}, you MUST provide one.
+     * </p>
+     * <h2>Using NIO</h2>
+     *
+     * <pre>{@code
+     * ChecksumInputStream s = ChecksumInputStream.builder()
+     *   .setPath(Paths.get("MyFile.xml"))
+     *   .setChecksum(new CRC32())

Review Comment:
   Right! I'll also document using a threshold separately.



##########
src/main/java/org/apache/commons/io/input/ChecksumInputStream.java:
##########
@@ -0,0 +1,208 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.commons.io.input;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.CheckedInputStream;
+import java.util.zip.Checksum;
+
+import org.apache.commons.io.build.AbstractStreamBuilder;
+
+/**
+ * Automatically verifies a {@link Checksum} value once the stream is 
exhausted.
+ * <p>
+ * If the {@link Checksum} does not meet the expected value when exhausted, 
then the input stream throws a
+ * {@link IOException}.
+ * </p>
+ * <p>
+ * If you do not need the verification or threshold feature, then use a plain 
{@link CheckedInputStream}.
+ * </p>
+ *
+ * @since 2.16.0
+ */
+public final class ChecksumInputStream extends CountingInputStream {
+
+    // @formatter:off
+    /**
+     * Builds a new {@link ChecksumInputStream} instance.
+     * <p>
+     * There is no default {@link Checksum}, you MUST provide one.
+     * </p>
+     * <h2>Using NIO</h2>
+     *
+     * <pre>{@code
+     * ChecksumInputStream s = ChecksumInputStream.builder()
+     *   .setPath(Paths.get("MyFile.xml"))
+     *   .setChecksum(new CRC32())
+     *   .get();
+     * }</pre>
+     *
+     * <h2>Using IO</h2>
+     *
+     * <pre>{@code
+     * ChecksumInputStream s = ChecksumInputStream.builder()
+     *   .setFile(new File("MyFile.xml"))
+     *   .setChecksum(new CRC32())
+     *   .get();
+     * }</pre>
+     */
+    // @formatter:on
+    public static class Builder extends 
AbstractStreamBuilder<ChecksumInputStream, Builder> {
+
+        /**
+         * There is no default checksum, you MUST provide one. This avoids any 
issue with a default {@link Checksum}
+         * being proven deficient or insecure in the future.
+         */
+        private Checksum checksum;
+
+        /**
+         * The count threshold to limit how much input is consumed to update 
the {@link Checksum} before the input
+         * stream validate its value.
+         * <p>
+         * By default, all input updates the {@link Checksum}.
+         * </p>
+         */
+        private long countThreshold = -1;
+
+        /**
+         * The expected {@link Checksum} value.
+         */
+        private long expectedChecksumValue;
+
+        /**
+         * Constructs a new instance.
+         * <p>
+         * This builder use the aspect InputStream.

Review Comment:
   I'll rephrase.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to