Example #1
0
 /**
  * Doesn't write the file atomically. Logs, but doesn't throw upon failure.
  *
  * @param file can't be null.
  * @param userId only for logging.
  * @param content
  * @param errorLevel if true log an error level message; otherwise warning level.
  */
 private void touchFile(File file, byte[] content, int userId, boolean errorLevel) {
   OutputStream out = null;
   try {
     file.getParentFile().mkdirs();
     out = new FileOutputStream(file);
     out.write(content);
     out.close();
     out = null;
   } catch (IOException ioe) {
     LogMessageGen lmg = new LogMessageGen();
     lmg.setSubject("Unable to touch cache file");
     lmg.param(LoggingConsts.USER_ID, userId);
     lmg.param(LoggingConsts.FILENAME, file.getAbsolutePath());
     lmg.param(LoggingConsts.CONTENT, content);
     if (errorLevel) {
       m_logCategory.error(lmg.toString(), ioe);
     } else {
       m_logCategory.warn(lmg.toString(), ioe);
     }
   } finally {
     // normally closed above; just for leak prevention.
     IOUtils.safeClose(out, false, m_logCategory);
   }
 }