From d6410204dbf392d37b8efbff00ab8dfdbf557e07 Mon Sep 17 00:00:00 2001 From: kmannthe Date: Sun, 30 Jan 2022 19:53:19 -0800 Subject: [PATCH] Fix excaping resourece round 3 in SmithWatermanUnitTest.java Signed-off-by: Keith Mannthey --- .../smithwaterman/SmithWatermanUnitTest.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/test/java/com/intel/gkl/smithwaterman/SmithWatermanUnitTest.java b/src/test/java/com/intel/gkl/smithwaterman/SmithWatermanUnitTest.java index 202cca3b..0287f4a8 100644 --- a/src/test/java/com/intel/gkl/smithwaterman/SmithWatermanUnitTest.java +++ b/src/test/java/com/intel/gkl/smithwaterman/SmithWatermanUnitTest.java @@ -216,28 +216,37 @@ public void simpleTest() { try { final File inputFile = new File(smithwatermanData); - long inputBytes = inputFile.length(); final FileReader input = new FileReader(inputFile); final BufferedReader in = new BufferedReader(input); byte[] ref; byte[] alt; - String refString, altString; + String refString = new String(""), altString = new String(""); SWParameters SWparameters = new SWParameters(200, -150, -260, -11); //SWParameters SWparameters = new SWParameters(3, -1, -4, -3); SWOverhangStrategy SWstrategy = SWOverhangStrategy.SOFTCLIP; - refString = in.readLine(); - while(refString !=null) { + try { + refString = in.readLine(); + } catch (IOException e) {System.err.println("Caught IOException: " + e.getMessage());} + + while(refString !=null) { ref = refString.getBytes("UTF-8"); - altString = in.readLine(); - alt = altString.getBytes("UTF-8"); + try { + altString = in.readLine(); + } catch (IOException e) {System.err.println("Caught IOException: " + e.getMessage());} + alt = altString.getBytes("UTF-8"); //Get the results for one pair - SWNativeAlignerResult result = smithWaterman.align(refString.getBytes("UTF-8"), altString.getBytes("UTF-8"), SWparameters, SWstrategy); - refString = in.readLine(); + SWNativeAlignerResult result = smithWaterman.align(refString.getBytes("UTF-8"), altString.getBytes("UTF-8"), SWparameters, SWstrategy); + + try { + refString = in.readLine(); + } catch (IOException e) {System.err.println("Caught IOException: " + e.getMessage());} + + } in.close(); input.close();