title: how to avoid sonar "Resouces should be closed" blocker warning
body: <p>I don't want to close RandomAccessFile immediately, but it will warn "Resources should be closed" when sonar scan. How to avoid this? Example code like followings:</p>
  
  <pre><code>public class AccessFileTest {
      private static RandomAccessFile accessFile;
      private static FileChannel fileChannel;
      private static long maxFileLength = 1024 * 1024;
      private static long currentFileLenth = 0;
  
      public static void main(String[] args) {
          for (int i = 0; i &lt; 1000; i++) {
              write("test");
          }
      }
  
      private static void write(String text) {
          try {
              if (accessFile == null) {
                  accessFile = new RandomAccessFile("", "rw");
                  fileChannel = accessFile.getChannel();
              }
              ByteBuffer buffer = ByteBuffer.wrap(text.getBytes());
              fileChannel.write(buffer);
              closeAccessFileIfNeed(text.getBytes());
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      private static void closeAccessFileIfNeed(byte[] bytes) throws IOException {
          currentFileLenth += bytes.length;
          if (currentFileLenth &gt;= maxFileLength) {
              accessFile.close();
          }
      }
  }
  </code></pre>