Skip to content

Commit 10d9e04

Browse files
committed
Deprecate BaseNCodec.isWhiteSpace(byte) and use
Character.isWhitespace(int)
1 parent 9d1dcc9 commit 10d9e04

5 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ The <action> type attribute can be add,update,fix,remove.
5757
<action dev="kinow" type="fix" due-to="Marc Wrobel">Fix several typos, improve writing in some javadocs #139.</action>
5858
<action dev="ggregory" type="fix" due-to="Gary Gregory">BaseNCodecOutputStream.eof() should not throw IOException.</action>
5959
<action dev="ggregory" type="fix" due-to="Gary Gregory">Javadoc improvements and cleanups.</action>
60+
<action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate BaseNCodec.isWhiteSpace(byte) and use Character.isWhitespace(int).</action>
6061
<!-- ADD -->
6162
<action issue="CODEC-296" dev="mattsicker" type="add" due-to="Matt Sicker">Add support for Blake3 family of hashes.</action>
6263
<action dev="ggregory" type="add">Add github/codeql-action.</action>

src/main/java/org/apache/commons/codec/binary/Base32.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public Base32(final int lineLength, final byte[] lineSeparator, final boolean us
335335
}
336336
this.decodeSize = this.encodeSize - 1;
337337

338-
if (isInAlphabet(padding) || isWhiteSpace(padding)) {
338+
if (isInAlphabet(padding) || Character.isWhitespace(padding)) {
339339
throw new IllegalArgumentException("pad must not be in alphabet or whitespace");
340340
}
341341
}

src/main/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public static boolean isBase64(final byte octet) {
389389
*/
390390
public static boolean isBase64(final byte[] arrayOctet) {
391391
for (final byte element : arrayOctet) {
392-
if (!isBase64(element) && !isWhiteSpace(element)) {
392+
if (!isBase64(element) && !Character.isWhitespace(element)) {
393393
return false;
394394
}
395395
}

src/main/java/org/apache/commons/codec/binary/BaseNCodec.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,15 @@ public static byte[] getChunkSeparator() {
277277

278278
/**
279279
* Checks if a byte value is whitespace or not.
280-
* Whitespace is taken to mean: space, tab, CR, LF
281280
* @param byteToCheck
282281
* the byte to check
283282
* @return true if byte is whitespace, false otherwise
283+
* @see Character#isWhitespace(int)
284+
* @deprecated Use {@link Character#isWhitespace(int)}.
284285
*/
286+
@Deprecated
285287
protected static boolean isWhiteSpace(final byte byteToCheck) {
286-
switch (byteToCheck) {
287-
case ' ' :
288-
case '\n' :
289-
case '\r' :
290-
case '\t' :
291-
return true;
292-
default :
293-
return false;
294-
}
288+
return Character.isWhitespace(byteToCheck);
295289
}
296290

297291
/**
@@ -641,7 +635,7 @@ boolean hasData(final Context context) { // package protected for access from I
641635
public boolean isInAlphabet(final byte[] arrayOctet, final boolean allowWSPad) {
642636
for (final byte octet : arrayOctet) {
643637
if (!isInAlphabet(octet) &&
644-
(!allowWSPad || (octet != pad) && !isWhiteSpace(octet))) {
638+
(!allowWSPad || (octet != pad) && !Character.isWhitespace(octet))) {
645639
return false;
646640
}
647641
}

src/test/java/org/apache/commons/codec/binary/BaseNCodecTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ public void testBaseNCodec() {
105105
//
106106
@Test
107107
public void testIsWhiteSpace() {
108-
assertTrue(BaseNCodec.isWhiteSpace((byte) ' '));
109-
assertTrue(BaseNCodec.isWhiteSpace((byte) '\n'));
110-
assertTrue(BaseNCodec.isWhiteSpace((byte) '\r'));
111-
assertTrue(BaseNCodec.isWhiteSpace((byte) '\t'));
108+
assertTrue(Character.isWhitespace((byte) ' '));
109+
assertTrue(Character.isWhitespace((byte) '\n'));
110+
assertTrue(Character.isWhitespace((byte) '\r'));
111+
assertTrue(Character.isWhitespace((byte) '\t'));
112+
assertTrue(Character.isWhitespace((byte) '\f'));
113+
assertTrue(Character.isWhitespace((byte) '\u000B'));
114+
for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
115+
final byte byteToCheck = b;
116+
assertEquals(Character.isWhitespace(b), Character.isWhitespace(byteToCheck));
117+
}
112118
}
113119
//
114120
// @Test

0 commit comments

Comments
 (0)