Deprecate HexDump#EOL in favor of System#lineSeparator()
Javadoc; format tweaks.
MODIFY
src/main/java/org/apache/commons/io/HexDump.java
src/main/java/org/apache/commons/io/HexDump.java
* <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 =
{
{
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
* 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 static void dump(final byte[] data, final long offset,
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 static void dump(final byte[] data, final long offset,
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 @@ private static StringBuilder dump(final StringBuilder _cbuffer, final byte value
}
/**
- * 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

MODIFY
src/test/java/org/apache/commons/io/HexDumpTest.java
src/test/java/org/apache/commons/io/HexDumpTest.java
@@ -39,10 +39,10 @@ public void testDump() throws IOException {
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 void testDump() throws IOException {
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 void testDump() throws IOException {
// 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 void testDump() throws IOException {
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 void testDump() throws IOException {
// 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 void testDump() throws IOException {
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 void testDump() throws IOException {
// 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 void testDump() throws IOException {
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");

Deprecate HexDump#EOL in favor of System#lineSeparator()

Javadoc; format tweaks.