Skip to content

Commit

Permalink
Use try-with-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
runningcode committed Apr 10, 2017
1 parent 99ee18e commit 8f04b59
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@ public static String getRelativePath(File root, File f) {

@SuppressWarnings("ResultOfMethodCallIgnored")
public static void copyResourceToProject(String resource, File destination) {
try {
InputStream inputStream = FileUtil.class.getResourceAsStream(resource);
try (InputStream inputStream = FileUtil.class.getResourceAsStream(resource);
OutputStream outputStream = new FileOutputStream(destination)) {
destination.getParentFile().mkdirs();
OutputStream outputStream = new FileOutputStream(destination);
IOUtils.copy(inputStream, outputStream);
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
} catch (IOException e) {
throw new IllegalStateException(e);
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ final class ReplaceUtil {

@SuppressWarnings("ResultOfMethodCallIgnored")
static void copyResourceToProject(String resource, File destination, Map<String, String> templates) {
try {
InputStream inputStream = FileUtil.class.getResourceAsStream(resource);
try (InputStream inputStream = FileUtil.class.getResourceAsStream(resource);
InputStreamReader reader = new InputStreamReader(inputStream);
TemplateReader replacingReader = new TemplateReader(reader, new TemplateMapResolver(templates));
OutputStream outputStream = new FileOutputStream(destination)){
destination.getParentFile().mkdirs();
InputStreamReader reader = new InputStreamReader(inputStream);
TemplateReader replacingReader = new TemplateReader(reader, new TemplateMapResolver(templates));

OutputStream outputStream = new FileOutputStream(destination);
IOUtils.copy(replacingReader, outputStream);
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
} catch (IOException e) {
throw new IllegalStateException(e);
throw new RuntimeException(e);
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.

0 comments on commit 8f04b59

Please sign in to comment.