Skip to content

Commit 143dd52

Browse files
committed
Internal refactoring
1 parent 42ac996 commit 143dd52

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ public abstract class BaseNCodec implements BinaryEncoder, BinaryDecoder {
5858
*/
5959
public abstract static class AbstractBuilder<T, B extends AbstractBuilder<T, B>> implements Supplier<T> {
6060

61+
/**
62+
* Clones the given array or returns a default array if the array is null.
63+
*
64+
* @param array The array to test and clone if not null.
65+
* @param defaultArray The default array to return if the array is null.
66+
* @return A clone of the array or the default array if the array is null.
67+
*/
68+
static byte[] clone(final byte[] array, final byte[] defaultArray) {
69+
return array != null ? array.clone() : defaultArray;
70+
}
71+
6172
private int unencodedBlockSize;
6273
private int encodedBlockSize;
6374
private CodecPolicy decodingPolicy = DECODING_POLICY_DEFAULT;
@@ -132,7 +143,7 @@ int getUnencodedBlockSize() {
132143
* @since 1.20.0
133144
*/
134145
public B setDecodeTable(final byte[] decodeTable) {
135-
this.decodeTable = decodeTable != null ? decodeTable.clone() : null;
146+
this.decodeTable = clone(decodeTable, null);
136147
return asThis();
137148
}
138149

@@ -176,7 +187,7 @@ B setEncodedBlockSize(final int encodedBlockSize) {
176187
* @return {@code this} instance.
177188
*/
178189
public B setEncodeTable(final byte... encodeTable) {
179-
this.encodeTable = encodeTable != null ? encodeTable.clone() : defaultEncodeTable;
190+
this.encodeTable = clone(encodeTable, defaultEncodeTable);
180191
return asThis();
181192
}
182193

@@ -209,7 +220,7 @@ public B setLineLength(final int lineLength) {
209220
* @return {@code this} instance.
210221
*/
211222
public B setLineSeparator(final byte... lineSeparator) {
212-
this.lineSeparator = lineSeparator != null ? lineSeparator.clone() : CHUNK_SEPARATOR;
223+
this.lineSeparator = clone(lineSeparator , CHUNK_SEPARATOR);
213224
return asThis();
214225
}
215226

0 commit comments

Comments
 (0)