Skip to content

Commit

Permalink
HWKMETRICS-182: Use try-with-resources around the streams.
Browse files Browse the repository at this point in the history
  • Loading branch information
mwringe committed Sep 23, 2015
1 parent 6bb09b5 commit 70e11e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
Expand Up @@ -54,20 +54,17 @@ public BasicAuthentication() throws IOException {
File passwdFile = new File(HTPASSWD_FILE);
if (passwdFile.exists() && passwdFile.isFile()) {

BufferedReader reader = new BufferedReader(new FileReader(passwdFile));

String line = reader.readLine();
while (line != null) {
String[] values = line.split(":", 2);
if (values.length == 2) {
users.put(values[0], values[1]);
try (BufferedReader reader = new BufferedReader(new FileReader(passwdFile))) {
String line = reader.readLine();
while (line != null) {
String[] values = line.split(":", 2);
if (values.length == 2) {
users.put(values[0], values[1]);
}

line = reader.readLine();
}

line = reader.readLine();
}

reader.close();

}
}

Expand Down
Expand Up @@ -94,12 +94,13 @@ private boolean isAuthorized(String method, String token, String projectId) {
connection.setRequestProperty("Authorization", token);

//Add the body
OutputStream outputStream = connection.getOutputStream();
for (byte b : generateSubjectAccessReview(projectId, verb).getBytes()) {
outputStream.write(b);
try (
OutputStream outputStream = connection.getOutputStream();
) {
for (byte b : generateSubjectAccessReview(projectId, verb).getBytes()) {
outputStream.write(b);
}
}
outputStream.flush();
outputStream.close();

//Perform the Operation
connection.connect();
Expand Down

0 comments on commit 70e11e6

Please sign in to comment.