Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Memory Management with FileChannels
    primarykey
    data
    text
    <p>I'm using the checkForErrors method shown below to check for errors in a txt file. The method performs an expected, expect that the OS File Handle associated with method parameter f is not being released. This causes a downstream external .exe to fail with the error message "The process cannot access the file because it is being used by another process."</p> <p>Are they any obvious memory management issues that I failed to address?</p> <pre><code>private boolean checkForErrors(File f) { FileInputStream fis = null; FileChannel fc = null; try { if (!f.exists()) { return true; } // get a Channel for the source file fis = new FileInputStream(f); fc = fis.getChannel(); Pattern errorPattern = Pattern.compile("ERROR"); Pattern eoPattern = Pattern.compile("END OF OUTPUT "); // get a CharBuffer from the source file ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, (int) fc.size()); Charset cs = Charset.forName("8859_1"); CharsetDecoder cd = cs.newDecoder(); CharBuffer cb = cd.decode(bb); // check for the presence of the ERROR keyword Matcher eP = errorPattern.matcher(cb); if (eP.find()) { return true; } // check for the ABSENCE of the end of output keywords Matcher eoP = eoPattern.matcher(cb); if (!eoP.find()) { return true; } } catch (IOException ex) { LOG.log(Level.INFO, null, ex); return true; } finally { try { if (fc != null) { fc.close(); fc = null; } if (fis != null) { fis.close(); fis = null; } } catch (IOException ex) { LOG.log(Level.INFO, null, ex); } } return false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload