Skip to content

Commit 78b5a4a

Browse files
author
Gary Gregory
committed
Deprecate HexDump#EOL in favor of System#lineSeparator()
Javadoc; format tweaks.
1 parent 7566f55 commit 78b5a4a

2 files changed

Lines changed: 29 additions & 22 deletions

File tree

src/main/java/org/apache/commons/io/HexDump.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,20 @@
2626
* <p>
2727
* Provides a single function to take an array of bytes and display it
2828
* in hexadecimal form.
29+
* </p>
2930
* <p>
3031
* Origin of code: POI.
31-
*
32+
* </p>
3233
*/
3334
public class HexDump {
3435

3536
/**
3637
* The line-separator (initializes to "line.separator" system property.
38+
*
39+
* @deprecated Use {@link System#lineSeparator()}.
3740
*/
38-
public static final String EOL =
39-
System.getProperty("line.separator");
41+
@Deprecated
42+
public static final String EOL = System.lineSeparator();
4043

4144
private static final char[] HEX_CODES =
4245
{
@@ -48,8 +51,9 @@ public class HexDump {
4851
{
4952
28, 24, 20, 16, 12, 8, 4, 0
5053
};
54+
5155
/**
52-
* Dump an array of bytes to an OutputStream. The output is formatted
56+
* Dumps an array of bytes to an OutputStream. The output is formatted
5357
* for human inspection, with a hexadecimal offset followed by the
5458
* hexadecimal values of the next 16 bytes of data and the printable ASCII
5559
* characters (if any) that those bytes represent printed per each line
@@ -61,9 +65,11 @@ public class HexDump {
6165
* offset argument should be set to 2048. The offset value printed
6266
* at the beginning of each line indicates where in that larger entity
6367
* the first byte on that line is located.
68+
* </p>
6469
* <p>
6570
* All bytes between the given index (inclusive) and the end of the
6671
* data array are dumped.
72+
* </p>
6773
*
6874
* @param data the byte array to be dumped
6975
* @param offset offset of the byte array within a larger entity
@@ -111,16 +117,17 @@ public static void dump(final byte[] data, final long offset,
111117
buffer.append('.');
112118
}
113119
}
114-
buffer.append(EOL);
120+
buffer.append(System.lineSeparator());
115121
// make explicit the dependency on the default encoding
116122
stream.write(buffer.toString().getBytes(Charset.defaultCharset()));
117123
stream.flush();
118124
buffer.setLength(0);
119125
display_offset += chars_read;
120126
}
121127
}
128+
122129
/**
123-
* Dump a byte value into a StringBuilder.
130+
* Dumps a byte value into a StringBuilder.
124131
*
125132
* @param _cbuffer the StringBuilder to dump the value in
126133
* @param value the byte value to be dumped
@@ -134,7 +141,7 @@ private static StringBuilder dump(final StringBuilder _cbuffer, final byte value
134141
}
135142

136143
/**
137-
* Dump a long value into a StringBuilder.
144+
* Dumps a long value into a StringBuilder.
138145
*
139146
* @param _lbuffer the StringBuilder to dump the value in
140147
* @param value the long value to be dumped

src/test/java/org/apache/commons/io/HexDumpTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public void testDump() throws IOException {
3939
ByteArrayOutputStream stream = new ByteArrayOutputStream();
4040

4141
HexDump.dump(testArray, 0, stream, 0);
42-
byte[] outputArray = new byte[16 * (73 + HexDump.EOL.length())];
42+
byte[] outputArray = new byte[16 * (73 + System.lineSeparator().length())];
4343

4444
for (int j = 0; j < 16; j++) {
45-
int offset = (73 + HexDump.EOL.length()) * j;
45+
int offset = (73 + System.lineSeparator().length()) * j;
4646

4747
outputArray[offset++] = (byte) '0';
4848
outputArray[offset++] = (byte) '0';
@@ -61,7 +61,7 @@ public void testDump() throws IOException {
6161
for (int k = 0; k < 16; k++) {
6262
outputArray[offset++] = (byte) toAscii(j * 16 + k);
6363
}
64-
System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset, HexDump.EOL.getBytes().length);
64+
System.arraycopy(System.lineSeparator().getBytes(), 0, outputArray, offset, System.lineSeparator().getBytes().length);
6565
}
6666
byte[] actualOutput = stream.toByteArray();
6767

@@ -73,9 +73,9 @@ public void testDump() throws IOException {
7373
// verify proper behavior with non-zero offset
7474
stream = new ByteArrayOutputStream();
7575
HexDump.dump(testArray, 0x10000000, stream, 0);
76-
outputArray = new byte[16 * (73 + HexDump.EOL.length())];
76+
outputArray = new byte[16 * (73 + System.lineSeparator().length())];
7777
for (int j = 0; j < 16; j++) {
78-
int offset = (73 + HexDump.EOL.length()) * j;
78+
int offset = (73 + System.lineSeparator().length()) * j;
7979

8080
outputArray[offset++] = (byte) '1';
8181
outputArray[offset++] = (byte) '0';
@@ -94,8 +94,8 @@ public void testDump() throws IOException {
9494
for (int k = 0; k < 16; k++) {
9595
outputArray[offset++] = (byte) toAscii(j * 16 + k);
9696
}
97-
System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset,
98-
HexDump.EOL.getBytes().length);
97+
System.arraycopy(System.lineSeparator().getBytes(), 0, outputArray, offset,
98+
System.lineSeparator().getBytes().length);
9999
}
100100
actualOutput = stream.toByteArray();
101101
assertEquals(outputArray.length, actualOutput.length, "array size mismatch");
@@ -106,9 +106,9 @@ public void testDump() throws IOException {
106106
// verify proper behavior with negative offset
107107
stream = new ByteArrayOutputStream();
108108
HexDump.dump(testArray, 0xFF000000, stream, 0);
109-
outputArray = new byte[16 * (73 + HexDump.EOL.length())];
109+
outputArray = new byte[16 * (73 + System.lineSeparator().length())];
110110
for (int j = 0; j < 16; j++) {
111-
int offset = (73 + HexDump.EOL.length()) * j;
111+
int offset = (73 + System.lineSeparator().length()) * j;
112112

113113
outputArray[offset++] = (byte) 'F';
114114
outputArray[offset++] = (byte) 'F';
@@ -127,8 +127,8 @@ public void testDump() throws IOException {
127127
for (int k = 0; k < 16; k++) {
128128
outputArray[offset++] = (byte) toAscii(j * 16 + k);
129129
}
130-
System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset,
131-
HexDump.EOL.getBytes().length);
130+
System.arraycopy(System.lineSeparator().getBytes(), 0, outputArray, offset,
131+
System.lineSeparator().getBytes().length);
132132
}
133133
actualOutput = stream.toByteArray();
134134
assertEquals(outputArray.length, actualOutput.length, "array size mismatch");
@@ -139,9 +139,9 @@ public void testDump() throws IOException {
139139
// verify proper behavior with non-zero index
140140
stream = new ByteArrayOutputStream();
141141
HexDump.dump(testArray, 0x10000000, stream, 0x81);
142-
outputArray = new byte[8 * (73 + HexDump.EOL.length()) - 1];
142+
outputArray = new byte[8 * (73 + System.lineSeparator().length()) - 1];
143143
for (int j = 0; j < 8; j++) {
144-
int offset = (73 + HexDump.EOL.length()) * j;
144+
int offset = (73 + System.lineSeparator().length()) * j;
145145

146146
outputArray[offset++] = (byte) '1';
147147
outputArray[offset++] = (byte) '0';
@@ -171,8 +171,8 @@ public void testDump() throws IOException {
171171
outputArray[offset++] = (byte) toAscii(index);
172172
}
173173
}
174-
System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset,
175-
HexDump.EOL.getBytes().length);
174+
System.arraycopy(System.lineSeparator().getBytes(), 0, outputArray, offset,
175+
System.lineSeparator().getBytes().length);
176176
}
177177
actualOutput = stream.toByteArray();
178178
assertEquals(outputArray.length, actualOutput.length, "array size mismatch");

0 commit comments

Comments
 (0)