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


##########
src/main/java/org/apache/commons/io/input/TrailerInputStream.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * Licensed 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.io.OutputStream;
+import org.apache.commons.io.IOUtils;
+
+/**
+ * Reads the underlying input stream while holding back the trailer.
+ * 
+ * <p>
+ * "Normal" read calls read the underlying stream except the last few bytes 
(the trailer). The
+ * trailer is updated with each read call. The trailer can be gotten by one of 
the copyTrailer
+ * overloads.
+ * </p>
+ * 
+ * <p>
+ * It is safe to fetch the trailer at any time but the trailer will change 
with each read call
+ * until the underlying stream is EOF.
+ * </p>
+ * 
+ * <p>
+ * Useful, e.g., for handling checksums: payload is followed by a fixed size 
hash, so while
+ * streaming the payload the trailer finally contains the expected hash (this 
example needs
+ * extra caution to revert actions when the final checksum match fails).
+ * </p>
+ */
+public final class TrailerInputStream extends InputStream {
+
+    private final  InputStream source;

Review Comment:
   This class should extend `java.io.FilterInputStream` or  
`org.apache.commons.io.input.ProxyInputStream`.



##########
src/main/java/org/apache/commons/io/input/TrailerInputStream.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * Licensed 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.io.OutputStream;
+import org.apache.commons.io.IOUtils;
+
+/**
+ * Reads the underlying input stream while holding back the trailer.
+ * 
+ * <p>
+ * "Normal" read calls read the underlying stream except the last few bytes 
(the trailer). The
+ * trailer is updated with each read call. The trailer can be gotten by one of 
the copyTrailer
+ * overloads.
+ * </p>
+ * 
+ * <p>
+ * It is safe to fetch the trailer at any time but the trailer will change 
with each read call
+ * until the underlying stream is EOF.
+ * </p>
+ * 
+ * <p>
+ * Useful, e.g., for handling checksums: payload is followed by a fixed size 
hash, so while
+ * streaming the payload the trailer finally contains the expected hash (this 
example needs
+ * extra caution to revert actions when the final checksum match fails).
+ * </p>
+ */
+public final class TrailerInputStream extends InputStream {
+
+    private final  InputStream source;
+    /**
+     * Invariant: After every method call which exited without exception, the 
trailer has to be
+     * completely filled.
+     */
+    private final byte[] trailer;
+
+    /**
+     * Constructs the TrailerInputStream and initializes the trailer buffer.
+     * 
+     * <p>
+     * Reads exactly {@code trailerLength} bytes from {@code source}.
+     * </p>
+     * 
+     * @param source underlying stream from which is read.
+     * @param trailerLength the length of the trailer which is hold back (must 
be &gt;= 0).
+     * @throws IOException initializing the trailer buffer failed.
+     */
+    public TrailerInputStream(final InputStream source, final int 
trailerLength)

Review Comment:
   Use the Builder pattern to avoid constructor creep. For example 
`org.apache.commons.io.input.BOMInputStream.Builder`.
   



-- 
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