diff --git a/src/main/java/org/web3j/console/project/ProjectWriter.java b/src/main/java/org/web3j/console/project/ProjectWriter.java index 1a782a5..d85311d 100644 --- a/src/main/java/org/web3j/console/project/ProjectWriter.java +++ b/src/main/java/org/web3j/console/project/ProjectWriter.java @@ -14,10 +14,10 @@ import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.util.Objects; class ProjectWriter { @@ -31,9 +31,13 @@ private byte[] getBytes(final String file) { return file.getBytes(); } - final void copyResourceFile(final InputStream file, final String destinationPath) + final void copyResourceFile(final String file, final String destinationPath) throws IOException { - Files.copy(file, Paths.get(destinationPath), StandardCopyOption.REPLACE_EXISTING); + + Files.copy( + Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(file)), + Paths.get(destinationPath), + StandardCopyOption.REPLACE_EXISTING); } final void importSolidityProject(final File file, final String destination) throws IOException { diff --git a/src/main/java/org/web3j/console/project/TemplateProvider.java b/src/main/java/org/web3j/console/project/TemplateProvider.java index 1ae79da..c690a6b 100644 --- a/src/main/java/org/web3j/console/project/TemplateProvider.java +++ b/src/main/java/org/web3j/console/project/TemplateProvider.java @@ -26,7 +26,7 @@ public class TemplateProvider { private final String gradlewWrapperSettings; private final String gradlewBatScript; private final String gradlewScript; - private final InputStream gradlewJar; + private final String gradlewJar; private TemplateProvider( final String mainJavaClass, @@ -36,7 +36,7 @@ private TemplateProvider( final String gradlewWrapperSettings, final String gradlewBatScript, final String gradlewScript, - final InputStream gradlewJar) { + final String gradlewJar) { this.mainJavaClass = mainJavaClass; this.solidityProject = solidityProject; this.gradleBuild = gradleBuild; @@ -75,7 +75,7 @@ String getGradlewScript() { return gradlewScript; } - InputStream getGradlewJar() { + String getGradlewJar() { return gradlewJar; } @@ -87,7 +87,7 @@ public static class Builder { private String gradlewBatScript; private String gradlewScript; private String solidityProject; - private InputStream gradlewJar; + private String gradlewWraperJar; private Function packageNameReplacement = s -> s; private Function projectNameReplacement = s -> s; @@ -133,7 +133,7 @@ public Builder loadGradlewScript(final String name) throws IOException { } public Builder loadGradleJar(final String name) { - this.gradlewJar = getClass().getClassLoader().getResourceAsStream(name); + this.gradlewWraperJar = name; return this; } @@ -158,7 +158,7 @@ TemplateProvider build() { gradlewWrapperSettings, gradlewBatScript, gradlewScript, - gradlewJar); + gradlewWraperJar); } private String readFile(final String name) throws IOException {