diff --git a/src/main/java/net/locusworks/common/crypto/KeyFile.java b/src/main/java/net/locusworks/common/crypto/KeyFile.java index e512c04..9b71ce3 100644 --- a/src/main/java/net/locusworks/common/crypto/KeyFile.java +++ b/src/main/java/net/locusworks/common/crypto/KeyFile.java @@ -89,7 +89,7 @@ public class KeyFile implements AutoCloseable { try { this.key = ksh.isPrivate() ? kf.generatePrivateKey(ksh.getKeySpec()) : kf.generatePublicKey(ksh.getKeySpec()); this.encryptionType = ksh.getEncryptionType(); - return; + break; } catch (NullPointerException | InvalidKeySpecException ikse) { continue; } } diff --git a/src/main/java/net/locusworks/common/utils/FileReader.java b/src/main/java/net/locusworks/common/utils/FileReader.java index 5991e3a..63211e3 100644 --- a/src/main/java/net/locusworks/common/utils/FileReader.java +++ b/src/main/java/net/locusworks/common/utils/FileReader.java @@ -20,7 +20,7 @@ import net.locusworks.common.interfaces.AutoCloseableIterator; * @version 1.0.0 * @date 02/15/2018 */ -public class FileReader implements AutoCloseableIterator, Iterable { +public class FileReader implements AutoCloseableIterator, Iterable, AutoCloseable { private BufferedReader reader; private LineInfo info; diff --git a/src/test/java/net/locusworks/test/FileReaderTest.java b/src/test/java/net/locusworks/test/FileReaderTest.java index 5e8b6f6..9296da6 100644 --- a/src/test/java/net/locusworks/test/FileReaderTest.java +++ b/src/test/java/net/locusworks/test/FileReaderTest.java @@ -49,12 +49,14 @@ public class FileReaderTest { @Test public void testForLoop() { Integer lineCount = 0; - for(LineInfo s : new FileReader(Paths.get(TEST_FILE))) { - lineCount++; - Integer lineNumber = s.getLineNumber(); - Integer lineLength = s.getLine().length(); - Integer mapLineLength = numLines.get(lineNumber); - assertTrue(lineLength == (mapLineLength-1)); + try (FileReader fr = new FileReader(Paths.get(TEST_FILE))) { + for (LineInfo s : fr) { + lineCount++; + Integer lineNumber = s.getLineNumber(); + Integer lineLength = s.getLine().length(); + Integer mapLineLength = numLines.get(lineNumber); + assertTrue(lineLength == (mapLineLength-1)); + } } assertTrue(lineCount == numLines.size()); }