Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit a1726ac

Browse files
committed
Move code to Java 8
1 parent 69b9c5a commit a1726ac

File tree

5 files changed

+26
-33
lines changed

5 files changed

+26
-33
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ target/
44
.settings/
55
bin
66
*.iml
7+
.idea
78

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</distributionManagement>
3232

3333
<properties>
34-
<javaVersion>7</javaVersion>
34+
<javaVersion>8</javaVersion>
3535
<sisuVersion>0.3.5</sisuVersion>
3636
<project.build.outputTimestamp>2021-09-08T19:26:29Z</project.build.outputTimestamp>
3737
</properties>

src/main/java/org/sonatype/plexus/components/cipher/Base64.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
*
3131
*/
3232

33+
import java.util.Arrays;
34+
3335
/**
3436
* <p>Provides Base64 encoding and decoding as defined by RFC 2045.</p>
3537
*
@@ -114,9 +116,7 @@ public class Base64
114116

115117
// Populating the lookup and character arrays
116118
static {
117-
for (int i = 0; i < BASELENGTH; i++) {
118-
base64Alphabet[i] = (byte) -1;
119-
}
119+
Arrays.fill(base64Alphabet, (byte) -1);
120120
for (int i = 'Z'; i >= 'A'; i--) {
121121
base64Alphabet[i] = (byte) (i - 'A');
122122
}
@@ -174,8 +174,8 @@ public static boolean isArrayByteBase64(byte[] arrayOctect) {
174174
// return false;
175175
return true;
176176
}
177-
for (int i = 0; i < length; i++) {
178-
if (!isBase64(arrayOctect[i])) {
177+
for (byte b : arrayOctect) {
178+
if (!isBase64(b)) {
179179
return false;
180180
}
181181
}
@@ -454,15 +454,15 @@ static byte[] discardWhitespace(byte[] data) {
454454
byte groomedData[] = new byte[data.length];
455455
int bytesCopied = 0;
456456

457-
for (int i = 0; i < data.length; i++) {
458-
switch (data[i]) {
457+
for (byte datum : data) {
458+
switch (datum) {
459459
case (byte) ' ':
460460
case (byte) '\n':
461461
case (byte) '\r':
462462
case (byte) '\t':
463463
break;
464464
default:
465-
groomedData[bytesCopied++] = data[i];
465+
groomedData[bytesCopied++] = datum;
466466
}
467467
}
468468

@@ -486,9 +486,9 @@ static byte[] discardNonBase64(byte[] data) {
486486
byte groomedData[] = new byte[data.length];
487487
int bytesCopied = 0;
488488

489-
for (int i = 0; i < data.length; i++) {
490-
if (isBase64(data[i])) {
491-
groomedData[bytesCopied++] = data[i];
489+
for (byte datum : data) {
490+
if (isBase64(datum)) {
491+
groomedData[bytesCopied++] = datum;
492492
}
493493
}
494494

src/main/java/org/sonatype/plexus/components/cipher/DefaultPlexusCipher.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static String[] getServiceTypes()
161161
result.add(key.substring(0, ix));
162162
}
163163
}
164-
return result.toArray( new String[result.size()] );
164+
return result.toArray(new String[0]);
165165
}
166166

167167
/**
@@ -189,7 +189,7 @@ else if (key.startsWith("Alg.Alias." + serviceType + ".")) {
189189
}
190190
}
191191
}
192-
return result.toArray( new String[result.size()] );
192+
return result.toArray(new String[0]);
193193
}
194194

195195
// ---------------------------------------------------------------

src/test/java/org/sonatype/plexus/components/cipher/DefaultPlexusCipherTest.java

+11-19
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,13 @@ public void testDefaultAlgorithmExists()
8383
assertNotNull( "No Cipher providers found in the current environment", res );
8484

8585
System.out.println( "\n=== Available ciphers :" );
86-
for ( int i = 0; i < res.length; i++ )
87-
{
88-
System.out.println( res[i] );
86+
for (String re : res) {
87+
System.out.println(re);
8988
}
9089
System.out.println( "====================" );
9190

92-
for ( int i = 0; i < res.length; i++ )
93-
{
94-
String provider = res[i];
95-
if ( PBECipher.KEY_ALG.equalsIgnoreCase( provider ) )
91+
for (String provider : res) {
92+
if (PBECipher.KEY_ALG.equalsIgnoreCase(provider))
9693
return;
9794
}
9895

@@ -111,18 +108,13 @@ public void stestFindDefaultAlgorithm()
111108
String[] impls = DefaultPlexusCipher.getCryptoImpls( "Cipher" );
112109
assertNotNull( "No Cipher providers found in the current environment", impls );
113110

114-
for ( int i = 0; i < impls.length; i++ )
115-
try
116-
{
117-
String provider = impls[i];
118-
119-
System.out.print( provider );
120-
pc.encrypt( str, passPhrase );
121-
System.out.println( "------------------> Success !!!!!!" );
122-
}
123-
catch ( Exception e )
124-
{
125-
System.out.println( e.getMessage() );
111+
for (String impl : impls)
112+
try {
113+
System.out.print(impl);
114+
pc.encrypt(str, passPhrase);
115+
System.out.println("------------------> Success !!!!!!");
116+
} catch (Exception e) {
117+
System.out.println(e.getMessage());
126118
}
127119
}
128120

0 commit comments

Comments
 (0)