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 28, 2017
1 parent 45ba411 commit 43b46b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
1 change: 1 addition & 0 deletions buckw
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ setupBuckRun ( ) {
handleParams ( ) {
# Go directly to kill. Do not run okbuck.
if [[ "kill" == $1 ]]; then
echo "skipping okbuck"
SKIP_OKBUCK=true
fi
}
Expand Down
11 changes: 4 additions & 7 deletions buildSrc/src/main/java/com/uber/okbuck/core/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
destination.getParentFile().mkdirs();
OutputStream outputStream = new FileOutputStream(destination);
destination.getParentFile().mkdirs();
try (InputStream inputStream = FileUtil.class.getResourceAsStream(resource);
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
16 changes: 6 additions & 10 deletions buildSrc/src/main/java/com/uber/okbuck/core/util/ReplaceUtil.java
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);
destination.getParentFile().mkdirs();
InputStreamReader reader = new InputStreamReader(inputStream);
TemplateReader replacingReader = new TemplateReader(reader, new TemplateMapResolver(templates));

OutputStream outputStream = new FileOutputStream(destination);
destination.getParentFile().mkdirs();
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)){
IOUtils.copy(replacingReader, outputStream);
IOUtils.closeQuietly(inputStream);
IOUtils.closeQuietly(outputStream);
} catch (IOException e) {
throw new IllegalStateException(e);
throw new RuntimeException(e);
}
}

Expand Down

0 comments on commit 43b46b2

Please sign in to comment.