Skip to content

Commit

Permalink
Fix for #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Stewart committed Mar 21, 2012
1 parent 7aad2bd commit bb0346c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/java/com/jezhumble/javasysmon/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ public String slurp(String fileName) throws IOException {
public byte[] slurpToByteArray(String fileName) throws IOException {
File fileToRead = new File(fileName);
byte[] contents = new byte[(int) fileToRead.length()];
final InputStream inputStream = new FileInputStream(fileToRead);
inputStream.read(contents);
return contents;
InputStream inputStream = null;
try {
inputStream = new FileInputStream(fileToRead);
inputStream.read(contents);
return contents;
} finally {
if (inputStream != null) {
inputStream.close();
}
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/jezhumble/javasysmon/UnixPasswdParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
class UnixPasswdParser {

public HashMap parse(BufferedReader reader) {
if (reader == null) {
System.err.println("Error parsing password file: reader is null");
return new HashMap();
}

HashMap users = new HashMap();
try {
String line;
Expand All @@ -22,6 +27,12 @@ public HashMap parse(BufferedReader reader) {
} catch (IOException e) {
System.err.println("Error parsing password file: " + e.getMessage());
return new HashMap();
} finally {
try {
reader.close();
} catch (IOException e) {
System.err.println("Error closing reader: " + e.getMessage());
}
}
}

Expand Down

0 comments on commit bb0346c

Please sign in to comment.