diff --git a/buildSrc/src/main/java/com/uber/okbuck/core/util/FileUtil.java b/buildSrc/src/main/java/com/uber/okbuck/core/util/FileUtil.java index 3d469fcbe..6ef4a37b0 100644 --- a/buildSrc/src/main/java/com/uber/okbuck/core/util/FileUtil.java +++ b/buildSrc/src/main/java/com/uber/okbuck/core/util/FileUtil.java @@ -38,15 +38,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); } } diff --git a/buildSrc/src/main/java/com/uber/okbuck/core/util/ReplaceUtil.java b/buildSrc/src/main/java/com/uber/okbuck/core/util/ReplaceUtil.java index e72b51409..12a60ced2 100644 --- a/buildSrc/src/main/java/com/uber/okbuck/core/util/ReplaceUtil.java +++ b/buildSrc/src/main/java/com/uber/okbuck/core/util/ReplaceUtil.java @@ -18,18 +18,14 @@ final class ReplaceUtil { @SuppressWarnings("ResultOfMethodCallIgnored") static void copyResourceToProject(String resource, File destination, Map 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); } }