Skip to content

Commit

Permalink
Improve quality
Browse files Browse the repository at this point in the history
  • Loading branch information
dbmeneses committed Feb 8, 2016
1 parent f73dbaf commit 940fc61
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ private Notification convertToNotification(List<NotificationQueueDto> notificati
alreadyLoggedDeserializationIssue = true;
}
return null;
} catch (IOException e) {
throw new SonarException(UNABLE_TO_READ_NOTIFICATION, e);

} catch (ClassNotFoundException e) {
} catch (IOException | ClassNotFoundException e) {
throw new SonarException(UNABLE_TO_READ_NOTIFICATION, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ private File getReportFileDir() {
}

public void writeToFile(IssuesReport report, File toFile, boolean complete) {
Writer writer = null;
FileOutputStream fos = null;
try {
freemarker.log.Logger.selectLoggerLibrary(freemarker.log.Logger.LIBRARY_NONE);
freemarker.template.Configuration cfg = new freemarker.template.Configuration();
Expand All @@ -138,17 +136,14 @@ public void writeToFile(IssuesReport report, File toFile, boolean complete) {
root.put("complete", complete);

Template template = cfg.getTemplate("issuesreport.ftl");
fos = new FileOutputStream(toFile);
writer = new OutputStreamWriter(fos, fs.encoding());
template.process(root, writer);
writer.flush();

try (FileOutputStream fos = new FileOutputStream(toFile); Writer writer = new OutputStreamWriter(fos, fs.encoding())) {
template.process(root, writer);
writer.flush();
}
} catch (Exception e) {
throw new IllegalStateException("Fail to generate HTML Issues Report to: " + toFile, e);

} finally {
IOUtils.closeQuietly(writer);
IOUtils.closeQuietly(fos);
}
}

Expand All @@ -173,18 +168,11 @@ void copyDependencies(File toDir) throws URISyntaxException, IOException {
}

private void copyDependency(File target, String filename) {
InputStream input = null;
OutputStream output = null;
try {
input = getClass().getResourceAsStream("/org/sonar/batch/scan/report/issuesreport_files/" + filename);
output = new FileOutputStream(new File(target, filename));
try (InputStream input = getClass().getResourceAsStream("/org/sonar/batch/scan/report/issuesreport_files/" + filename);
OutputStream output = new FileOutputStream(new File(target, filename))) {
IOUtils.copy(input, output);

} catch (IOException e) {
throw new IllegalStateException("Fail to copy file " + filename + " to " + target, e);
} finally {
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,20 @@ public boolean handle(Row row, SqlStatement update) throws SQLException {

return true;
}
}

private static String ofNullableBytes(@Nullable byte[] shortBytes, @Nullable byte[] longBytes) {
byte[] result;
if (shortBytes == null) {
if (longBytes == null) {
return "";

private static String ofNullableBytes(@Nullable byte[] shortBytes, @Nullable byte[] longBytes) {
byte[] result;
if (shortBytes == null) {
if (longBytes == null) {
return "";
} else {
result = longBytes;
}
} else {
result = longBytes;
result = shortBytes;
}
} else {
result = shortBytes;
return new String(result, StandardCharsets.UTF_8);
}
return new String(result, StandardCharsets.UTF_8);
}

@Override
Expand Down

0 comments on commit 940fc61

Please sign in to comment.