Skip to content

Commit 4b95025

Browse files
committed
Make code fully Java 8 compatible
1 parent b93b53d commit 4b95025

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/main/java/de/jjohannes/gradle/javamodules/ExtraModuleInfoPluginExtension.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Here the class is used as extension that can be configured in the build script
1212
* and as input to the ExtraModuleInfoTransform that add the information to Jars.
1313
*/
14+
@SuppressWarnings("unused")
1415
public abstract class ExtraModuleInfoPluginExtension {
1516

1617
abstract public MapProperty<String, ModuleSpec> getModuleSpecs();

src/main/java/de/jjohannes/gradle/javamodules/ExtraModuleInfoTransform.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
import javax.annotation.Nullable;
2222
import java.io.BufferedReader;
2323
import java.io.ByteArrayInputStream;
24+
import java.io.ByteArrayOutputStream;
2425
import java.io.File;
2526
import java.io.IOException;
27+
import java.io.InputStream;
2628
import java.io.InputStreamReader;
2729
import java.io.OutputStream;
2830
import java.nio.charset.StandardCharsets;
@@ -234,7 +236,7 @@ private static Map<String, String[]> copyAndExtractProviders(JarInputStream inpu
234236
JarEntry jarEntry = inputStream.getNextJarEntry();
235237
Map<String, String[]> providers = new LinkedHashMap<>();
236238
while (jarEntry != null) {
237-
byte[] content = inputStream.readAllBytes();
239+
byte[] content = readAllBytes(inputStream);
238240
String entryName = jarEntry.getName();
239241
if (entryName.startsWith(SERVICES_PREFIX) && !entryName.equals(SERVICES_PREFIX)) {
240242
providers.put(entryName.substring(SERVICES_PREFIX.length()), extractImplementations(content));
@@ -324,7 +326,7 @@ private static void copyEntries(JarInputStream inputStream, JarOutputStream outp
324326
while (jarEntry != null) {
325327
try {
326328
outputStream.putNextEntry(jarEntry);
327-
outputStream.write(inputStream.readAllBytes());
329+
outputStream.write(readAllBytes(inputStream));
328330
outputStream.closeEntry();
329331
} catch (ZipException e) {
330332
if (!e.getMessage().startsWith("duplicate entry:")) {
@@ -334,4 +336,16 @@ private static void copyEntries(JarInputStream inputStream, JarOutputStream outp
334336
jarEntry = inputStream.getNextJarEntry();
335337
}
336338
}
339+
340+
public static byte[] readAllBytes(InputStream inputStream) throws IOException {
341+
final int bufLen = 4 * 0x400;
342+
byte[] buf = new byte[bufLen];
343+
int readLen;
344+
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
345+
while ((readLen = inputStream.read(buf, 0, bufLen)) != -1) {
346+
outputStream.write(buf, 0, readLen);
347+
}
348+
return outputStream.toByteArray();
349+
}
350+
}
337351
}

src/main/java/de/jjohannes/gradle/javamodules/ModuleInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/**
77
* Data class to hold the information that should be added as module-info.class to an existing Jar file.
88
*/
9+
@SuppressWarnings("unused")
910
public class ModuleInfo extends ModuleSpec {
1011

1112
private final String moduleVersion;

src/main/java/de/jjohannes/gradle/javamodules/ModuleSpec.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/**
88
* Details that real Modules and Automatic-Module-Names share.
99
*/
10+
@SuppressWarnings("unused")
1011
abstract public class ModuleSpec implements Serializable {
1112

1213
private final String identifier;

0 commit comments

Comments
 (0)