You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/12/30 12:25:03 UTC

[GitHub] [commons-io] garydgregory commented on a diff in pull request #418: [IO-784] Add support for Appendable to HexDump util

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


##########
src/main/java/org/apache/commons/io/HexDump.java:
##########
@@ -53,7 +56,26 @@ public class HexDump {
             };
 
     /**
-     * Dumps an array of bytes to an OutputStream. The output is formatted
+     * Dumps an array of bytes to an Appendable. The output is formatted
+     * for human inspection, with a hexadecimal offset followed by the
+     * hexadecimal values of the next 16 bytes of data and the printable ASCII
+     * characters (if any) that those bytes represent printed per each line
+     * of output.
+     *
+     * @param data  the byte array to be dumped
+     * @param out  the Appendable to which the data is to be written
+     *
+     * @throws IOException is thrown if anything goes wrong writing
+     *         the data to appendable
+     */
+

Review Comment:
   Remove whitespace between Javadoc and code.



##########
src/main/java/org/apache/commons/io/HexDump.java:
##########
@@ -53,7 +56,26 @@ public class HexDump {
             };
 
     /**
-     * Dumps an array of bytes to an OutputStream. The output is formatted
+     * Dumps an array of bytes to an Appendable. The output is formatted
+     * for human inspection, with a hexadecimal offset followed by the
+     * hexadecimal values of the next 16 bytes of data and the printable ASCII
+     * characters (if any) that those bytes represent printed per each line
+     * of output.
+     *
+     * @param data  the byte array to be dumped
+     * @param out  the Appendable to which the data is to be written
+     *
+     * @throws IOException is thrown if anything goes wrong writing
+     *         the data to appendable
+     */
+

Review Comment:
   Add Javadoc since tag to new public and protected elements. 



##########
src/main/java/org/apache/commons/io/HexDump.java:
##########
@@ -53,7 +56,26 @@ public class HexDump {
             };
 
     /**
-     * Dumps an array of bytes to an OutputStream. The output is formatted
+     * Dumps an array of bytes to an Appendable. The output is formatted
+     * for human inspection, with a hexadecimal offset followed by the
+     * hexadecimal values of the next 16 bytes of data and the printable ASCII
+     * characters (if any) that those bytes represent printed per each line
+     * of output.
+     *
+     * @param data  the byte array to be dumped
+     * @param out  the Appendable to which the data is to be written
+     *
+     * @throws IOException is thrown if anything goes wrong writing
+     *         the data to appendable
+     */
+
+    public static void dump(final byte[] data, final Appendable out)

Review Comment:
   Rename `out` to `appendable` so it has no chance of being confused with an Output* class.



##########
src/main/java/org/apache/commons/io/HexDump.java:
##########
@@ -118,14 +144,55 @@ public static void dump(final byte[] data, final long offset,
                 }
             }
             buffer.append(System.lineSeparator());
-            // make explicit the dependency on the default encoding
-            stream.write(buffer.toString().getBytes(Charset.defaultCharset()));
-            stream.flush();
+            out.append(buffer);
             buffer.setLength(0);
             display_offset += chars_read;
         }
     }
 
+    /**
+     * Dumps an array of bytes to an OutputStream. The output is formatted
+     * for human inspection, with a hexadecimal offset followed by the
+     * hexadecimal values of the next 16 bytes of data and the printable ASCII
+     * characters (if any) that those bytes represent printed per each line
+     * of output.
+     * <p>
+     * The offset argument specifies the start offset of the data array
+     * within a larger entity like a file or an incoming stream. For example,
+     * if the data array contains the third kibibyte of a file, then the
+     * offset argument should be set to 2048. The offset value printed
+     * at the beginning of each line indicates where in that larger entity
+     * the first byte on that line is located.
+     * </p>
+     * <p>
+     * All bytes between the given index (inclusive) and the end of the
+     * data array are dumped.
+     * </p>
+     *
+     * @param data  the byte array to be dumped
+     * @param offset  offset of the byte array within a larger entity
+     * @param stream  the OutputStream to which the data is to be
+     *               written
+     * @param index initial index into the byte array
+     *
+     * @throws IOException is thrown if anything goes wrong writing
+     *         the data to stream
+     * @throws ArrayIndexOutOfBoundsException if the index is
+     *         outside the data array's bounds
+     * @throws NullPointerException if the output stream is null
+     */
+    public static void dump(final byte[] data, final long offset,
+                            final OutputStream stream, final int index)
+            throws IOException, ArrayIndexOutOfBoundsException {
+        Objects.requireNonNull(stream, "stream");
+
+        // make explicit the dependency on the default encoding

Review Comment:
   This comment is not needed: "make explicit the dependency on the default encoding"



-- 
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: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org