File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
src/main/java/com/jezhumble/javasysmon Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -50,9 +50,16 @@ public String slurp(String fileName) throws IOException {
5050 public byte [] slurpToByteArray (String fileName ) throws IOException {
5151 File fileToRead = new File (fileName );
5252 byte [] contents = new byte [(int ) fileToRead .length ()];
53- final InputStream inputStream = new FileInputStream (fileToRead );
54- inputStream .read (contents );
55- return contents ;
53+ InputStream inputStream = null ;
54+ try {
55+ inputStream = new FileInputStream (fileToRead );
56+ inputStream .read (contents );
57+ return contents ;
58+ } finally {
59+ if (inputStream != null ) {
60+ inputStream .close ();
61+ }
62+ }
5663 }
5764
5865 /**
Original file line number Diff line number Diff line change 99class UnixPasswdParser {
1010
1111 public HashMap parse (BufferedReader reader ) {
12+ if (reader == null ) {
13+ System .err .println ("Error parsing password file: reader is null" );
14+ return new HashMap ();
15+ }
16+
1217 HashMap users = new HashMap ();
1318 try {
1419 String line ;
@@ -22,6 +27,12 @@ public HashMap parse(BufferedReader reader) {
2227 } catch (IOException e ) {
2328 System .err .println ("Error parsing password file: " + e .getMessage ());
2429 return new HashMap ();
30+ } finally {
31+ try {
32+ reader .close ();
33+ } catch (IOException e ) {
34+ System .err .println ("Error closing reader: " + e .getMessage ());
35+ }
2536 }
2637 }
2738
You can’t perform that action at this time.
0 commit comments