Refactored the test run of GrokAssembly to avoid double-closing

Former-commit-id: 8279c075543071cdebf9c1433b6e0b1b0366ed59
This commit is contained in:
Will Stranathan
2014-02-01 09:33:47 -05:00
parent 60625b9978
commit c9ac7401e8

View File

@@ -168,13 +168,29 @@ public class AssemblyAnalyzer extends AbstractAnalyzer {
while ((bread = is.read(buff)) >= 0) {
fos.write(buff, 0, bread);
}
fos.flush();
fos.close();
fos = null;
grokAssemblyExe = tempFile;
// Set the temp file to get deleted when we're done
grokAssemblyExe.deleteOnExit();
LOG.log(Level.INFO, "Extracted GrokAssembly.exe to {0}", grokAssemblyExe.getPath());
} catch (IOException ioe) {
LOG.log(Level.WARNING, "Could not extract GrokAssembly.exe: {0}", ioe.getMessage());
throw new AnalysisException("Could not extract GrokAssembly.exe", ioe);
} finally {
if (fos != null) {
try {
fos.close();
} catch (Exception e) {
LOG.fine("Error closing output stream");
}
}
if (is != null) {
try {
is.close();
} catch (Exception e) {
LOG.fine("Error closing input stream");
}
}
}
// Now, need to see if GrokAssembly actually runs from this location.
final List<String> args = buildArgumentList();
@@ -194,22 +210,6 @@ public class AssemblyAnalyzer extends AbstractAnalyzer {
}
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
} finally {
if (fos != null) {
try {
fos.close();
} catch (Exception e) {
LOG.fine("Error closing output stream");
}
}
if (is != null) {
try {
is.close();
} catch (Exception e) {
LOG.fine("Error closing input stream");
}
}
}
}
@Override