Skip to content

Commit 27c6dde

Browse files
Avoid C-style array declaration and use Java instead. (#108)
1 parent 80fffec commit 27c6dde

4 files changed

Lines changed: 23 additions & 23 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public int read() throws IOException {
144144
* if offset, len or buffer size are invalid
145145
*/
146146
@Override
147-
public int read(final byte array[], final int offset, final int len) throws IOException {
147+
public int read(final byte[] array, final int offset, final int len) throws IOException {
148148
Objects.requireNonNull(array, "array");
149149
if (offset < 0 || len < 0) {
150150
throw new IndexOutOfBoundsException();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public boolean isStrictDecoding() {
162162
* if offset, len or buffer size are invalid
163163
*/
164164
@Override
165-
public void write(final byte array[], final int offset, final int len) throws IOException {
165+
public void write(final byte[] array, final int offset, final int len) throws IOException {
166166
Objects.requireNonNull(array, "array");
167167
if (offset < 0 || len < 0) {
168168
throw new IndexOutOfBoundsException();

src/main/java/org/apache/commons/codec/digest/UnixCrypt.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@
3939
*/
4040
public class UnixCrypt {
4141

42-
private static final int CON_SALT[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42+
private static final int[] CON_SALT = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4343
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 5, 6,
4444
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
4545
34, 35, 36, 37, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
4646
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 0, 0, 0, 0 };
4747

48-
private static final int COV2CHAR[] = { 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70,
48+
private static final int[] COV2CHAR = { 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70,
4949
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102,
5050
103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122 };
5151

52-
private static final char SALT_CHARS[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"
52+
private static final char[] SALT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"
5353
.toCharArray();
5454

55-
private static final boolean SHIFT2[] = { false, false, true, true, true, true, true, true, false, true, true,
55+
private static final boolean[] SHIFT2 = { false, false, true, true, true, true, true, true, false, true, true,
5656
true, true, true, true, false };
5757

58-
private static final int SKB[][] = {
58+
private static final int[][] SKB = {
5959
{ 0, 16, 0x20000000, 0x20000010, 0x10000, 0x10010, 0x20010000, 0x20010010, 2048, 2064, 0x20000800,
6060
0x20000810, 0x10800, 0x10810, 0x20010800, 0x20010810, 32, 48, 0x20000020, 0x20000030, 0x10020,
6161
0x10030, 0x20010020, 0x20010030, 2080, 2096, 0x20000820, 0x20000830, 0x10820, 0x10830, 0x20010820,
@@ -114,7 +114,7 @@ public class UnixCrypt {
114114
0x4000822, 0x40822, 0x4040822, 10272, 0x4002820, 0x42820, 0x4042820, 10274, 0x4002822, 0x42822,
115115
0x4042822 } };
116116

117-
private static final int SPTRANS[][] = {
117+
private static final int[][] SPTRANS = {
118118
{ 0x820200, 0x20000, 0x80800000, 0x80820200, 0x800000, 0x80020200, 0x80020000, 0x80800000, 0x80020200,
119119
0x820200, 0x820000, 0x80000200, 0x80800200, 0x800000, 0, 0x80020000, 0x20000, 0x80000000,
120120
0x800200, 0x20200, 0x80820200, 0x820000, 0x80000200, 0x800200, 0x80000000, 512, 0x20200,
@@ -217,7 +217,7 @@ public static String crypt(final byte[] original, String salt) {
217217
buffer.setCharAt(1, charOne);
218218
final int eSwap0 = CON_SALT[charZero];
219219
final int eSwap1 = CON_SALT[charOne] << 4;
220-
final byte key[] = new byte[8];
220+
final byte[] key = new byte[8];
221221
Arrays.fill(key, (byte) 0);
222222

223223
final int originalLength = original.length;
@@ -226,9 +226,9 @@ public static String crypt(final byte[] original, String salt) {
226226
key[i] = (byte) (iChar << 1);
227227
}
228228

229-
final int schedule[] = desSetKey(key);
230-
final int out[] = body(schedule, eSwap0, eSwap1);
231-
final byte b[] = new byte[9];
229+
final int[] schedule = desSetKey(key);
230+
final int[] out = body(schedule, eSwap0, eSwap1);
231+
final byte[] b = new byte[9];
232232
intToFourBytes(out[0], b, 0);
233233
intToFourBytes(out[1], b, 4);
234234
b[8] = 0;
@@ -286,7 +286,7 @@ public static String crypt(final String original, final String salt) {
286286
return crypt(original.getBytes(StandardCharsets.UTF_8), salt);
287287
}
288288

289-
private static int[] body(final int schedule[], final int eSwap0, final int eSwap1) {
289+
private static int[] body(final int[] schedule, final int eSwap0, final int eSwap1) {
290290
int left = 0;
291291
int right = 0;
292292
int t = 0;
@@ -303,7 +303,7 @@ private static int[] body(final int schedule[], final int eSwap0, final int eSwa
303303
t = right;
304304
right = left >>> 1 | left << 31;
305305
left = t >>> 1 | t << 31;
306-
final int results[] = new int[2];
306+
final int[] results = new int[2];
307307
permOp(right, left, 1, 0x55555555, results);
308308
right = results[0];
309309
left = results[1];
@@ -319,7 +319,7 @@ private static int[] body(final int schedule[], final int eSwap0, final int eSwa
319319
permOp(right, left, 4, 0xf0f0f0f, results);
320320
right = results[0];
321321
left = results[1];
322-
final int out[] = new int[2];
322+
final int[] out = new int[2];
323323
out[0] = left;
324324
out[1] = right;
325325
return out;
@@ -330,7 +330,7 @@ private static int byteToUnsigned(final byte b) {
330330
return value < 0 ? value + 256 : value;
331331
}
332332

333-
private static int dEncrypt(int el, final int r, final int s, final int e0, final int e1, final int sArr[]) {
333+
private static int dEncrypt(int el, final int r, final int s, final int e0, final int e1, final int[] sArr) {
334334
int v = r ^ r >>> 16;
335335
int u = v & e0;
336336
v &= e1;
@@ -343,11 +343,11 @@ private static int dEncrypt(int el, final int r, final int s, final int e0, fina
343343
return el;
344344
}
345345

346-
private static int[] desSetKey(final byte key[]) {
347-
final int schedule[] = new int[32];
346+
private static int[] desSetKey(final byte[] key) {
347+
final int[] schedule = new int[32];
348348
int c = fourBytesToInt(key, 0);
349349
int d = fourBytesToInt(key, 4);
350-
final int results[] = new int[2];
350+
final int[] results = new int[2];
351351
permOp(d, c, 4, 0xf0f0f0f, results);
352352
d = results[0];
353353
c = results[1];
@@ -389,7 +389,7 @@ private static int[] desSetKey(final byte key[]) {
389389
return schedule;
390390
}
391391

392-
private static int fourBytesToInt(final byte b[], int offset) {
392+
private static int fourBytesToInt(final byte[] b, int offset) {
393393
int value = byteToUnsigned(b[offset++]);
394394
value |= byteToUnsigned(b[offset++]) << 8;
395395
value |= byteToUnsigned(b[offset++]) << 16;
@@ -403,14 +403,14 @@ private static int hPermOp(int a, final int n, final int m) {
403403
return a;
404404
}
405405

406-
private static void intToFourBytes(final int iValue, final byte b[], int offset) {
406+
private static void intToFourBytes(final int iValue, final byte[] b, int offset) {
407407
b[offset++] = (byte) (iValue & 0xff);
408408
b[offset++] = (byte) (iValue >>> 8 & 0xff);
409409
b[offset++] = (byte) (iValue >>> 16 & 0xff);
410410
b[offset++] = (byte) (iValue >>> 24 & 0xff);
411411
}
412412

413-
private static void permOp(int a, int b, final int n, final int m, final int results[]) {
413+
private static void permOp(int a, int b, final int n, final int m, final int[] results) {
414414
final int t = (a >>> n ^ b) & m;
415415
a ^= t << n;
416416
b ^= t;

src/main/java/org/apache/commons/codec/language/Soundex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public String soundex(String str) {
307307
if (str.isEmpty()) {
308308
return str;
309309
}
310-
final char out[] = {'0', '0', '0', '0'};
310+
final char[] out = {'0', '0', '0', '0'};
311311
int count = 0;
312312
final char first = str.charAt(0);
313313
out[count++] = first;

0 commit comments

Comments
 (0)