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-io.git
The following commit(s) were added to refs/heads/master by this push: new 78b5a4a1 Deprecate HexDump#EOL in favor of System#lineSeparator() 78b5a4a1 is described below commit 78b5a4a1371fad7eb98aa29ef2f9a2bf2c9ecd11 Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Wed Jun 15 15:00:43 2022 -0400 Deprecate HexDump#EOL in favor of System#lineSeparator() Javadoc; format tweaks. --- src/main/java/org/apache/commons/io/HexDump.java | 21 ++++++++++----- .../java/org/apache/commons/io/HexDumpTest.java | 30 +++++++++++----------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/apache/commons/io/HexDump.java b/src/main/java/org/apache/commons/io/HexDump.java index ab2ae8d6..6674668b 100644 --- a/src/main/java/org/apache/commons/io/HexDump.java +++ b/src/main/java/org/apache/commons/io/HexDump.java @@ -26,17 +26,20 @@ import java.util.Objects; * <p> * Provides a single function to take an array of bytes and display it * in hexadecimal form. + * </p> * <p> * Origin of code: POI. - * + * </p> */ public class HexDump { /** * The line-separator (initializes to "line.separator" system property. + * + * @deprecated Use {@link System#lineSeparator()}. */ - public static final String EOL = - System.getProperty("line.separator"); + @Deprecated + public static final String EOL = System.lineSeparator(); private static final char[] HEX_CODES = { @@ -48,8 +51,9 @@ public class HexDump { { 28, 24, 20, 16, 12, 8, 4, 0 }; + /** - * Dump an array of bytes to an OutputStream. The output is formatted + * 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 @@ -61,9 +65,11 @@ public class HexDump { * 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 @@ -111,7 +117,7 @@ public class HexDump { buffer.append('.'); } } - buffer.append(EOL); + buffer.append(System.lineSeparator()); // make explicit the dependency on the default encoding stream.write(buffer.toString().getBytes(Charset.defaultCharset())); stream.flush(); @@ -119,8 +125,9 @@ public class HexDump { display_offset += chars_read; } } + /** - * Dump a byte value into a StringBuilder. + * Dumps a byte value into a StringBuilder. * * @param _cbuffer the StringBuilder to dump the value in * @param value the byte value to be dumped @@ -134,7 +141,7 @@ public class HexDump { } /** - * Dump a long value into a StringBuilder. + * Dumps a long value into a StringBuilder. * * @param _lbuffer the StringBuilder to dump the value in * @param value the long value to be dumped diff --git a/src/test/java/org/apache/commons/io/HexDumpTest.java b/src/test/java/org/apache/commons/io/HexDumpTest.java index e47e8396..75ab9e79 100644 --- a/src/test/java/org/apache/commons/io/HexDumpTest.java +++ b/src/test/java/org/apache/commons/io/HexDumpTest.java @@ -39,10 +39,10 @@ public class HexDumpTest { ByteArrayOutputStream stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0, stream, 0); - byte[] outputArray = new byte[16 * (73 + HexDump.EOL.length())]; + byte[] outputArray = new byte[16 * (73 + System.lineSeparator().length())]; for (int j = 0; j < 16; j++) { - int offset = (73 + HexDump.EOL.length()) * j; + int offset = (73 + System.lineSeparator().length()) * j; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; @@ -61,7 +61,7 @@ public class HexDumpTest { for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toAscii(j * 16 + k); } - System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset, HexDump.EOL.getBytes().length); + System.arraycopy(System.lineSeparator().getBytes(), 0, outputArray, offset, System.lineSeparator().getBytes().length); } byte[] actualOutput = stream.toByteArray(); @@ -73,9 +73,9 @@ public class HexDumpTest { // verify proper behavior with non-zero offset stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0x10000000, stream, 0); - outputArray = new byte[16 * (73 + HexDump.EOL.length())]; + outputArray = new byte[16 * (73 + System.lineSeparator().length())]; for (int j = 0; j < 16; j++) { - int offset = (73 + HexDump.EOL.length()) * j; + int offset = (73 + System.lineSeparator().length()) * j; outputArray[offset++] = (byte) '1'; outputArray[offset++] = (byte) '0'; @@ -94,8 +94,8 @@ public class HexDumpTest { for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toAscii(j * 16 + k); } - System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset, - HexDump.EOL.getBytes().length); + System.arraycopy(System.lineSeparator().getBytes(), 0, outputArray, offset, + System.lineSeparator().getBytes().length); } actualOutput = stream.toByteArray(); assertEquals(outputArray.length, actualOutput.length, "array size mismatch"); @@ -106,9 +106,9 @@ public class HexDumpTest { // verify proper behavior with negative offset stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0xFF000000, stream, 0); - outputArray = new byte[16 * (73 + HexDump.EOL.length())]; + outputArray = new byte[16 * (73 + System.lineSeparator().length())]; for (int j = 0; j < 16; j++) { - int offset = (73 + HexDump.EOL.length()) * j; + int offset = (73 + System.lineSeparator().length()) * j; outputArray[offset++] = (byte) 'F'; outputArray[offset++] = (byte) 'F'; @@ -127,8 +127,8 @@ public class HexDumpTest { for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toAscii(j * 16 + k); } - System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset, - HexDump.EOL.getBytes().length); + System.arraycopy(System.lineSeparator().getBytes(), 0, outputArray, offset, + System.lineSeparator().getBytes().length); } actualOutput = stream.toByteArray(); assertEquals(outputArray.length, actualOutput.length, "array size mismatch"); @@ -139,9 +139,9 @@ public class HexDumpTest { // verify proper behavior with non-zero index stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0x10000000, stream, 0x81); - outputArray = new byte[8 * (73 + HexDump.EOL.length()) - 1]; + outputArray = new byte[8 * (73 + System.lineSeparator().length()) - 1]; for (int j = 0; j < 8; j++) { - int offset = (73 + HexDump.EOL.length()) * j; + int offset = (73 + System.lineSeparator().length()) * j; outputArray[offset++] = (byte) '1'; outputArray[offset++] = (byte) '0'; @@ -171,8 +171,8 @@ public class HexDumpTest { outputArray[offset++] = (byte) toAscii(index); } } - System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset, - HexDump.EOL.getBytes().length); + System.arraycopy(System.lineSeparator().getBytes(), 0, outputArray, offset, + System.lineSeparator().getBytes().length); } actualOutput = stream.toByteArray(); assertEquals(outputArray.length, actualOutput.length, "array size mismatch");