code: private void init() throws IOException {
          if (initialized.compareAndSet(false, true)) {
              log.debug("Init: {}", mode);
              // if the path is null, the consumer has been uninitialized
              if (path != null) {
                  if (log.isDebugEnabled()) {
                      Path parent = path.getParent();
                      log.debug("Parent abs: {} dir: {}", parent.isAbsolute(), Files.isDirectory(parent));
                  }
                  if (IClientStream.MODE_APPEND.equals(mode)) {
                      if (Files.notExists(path)) {
                          throw new IOException("File to be appended doesnt exist, verify the record mode");
                      }
                      log.debug("Path: {}\nRead: {} write: {} size: {}", path, Files.isReadable(path), Files.isWritable(path), Files.size(path));
                      writer = new FLVWriter(path, true);
                  } else if (IClientStream.MODE_RECORD.equals(mode)) {
                      try {
                          // delete existing file
                          if (Files.deleteIfExists(path)) {
                              log.debug("File deleted");
                          }
                          // ensure parent dirs exist
                          Files.createDirectories(path.getParent());
                          // create the file
                          path = Files.createFile(path);
                      } catch (IOException ioe) {
                          log.error("File creation error: {}", ioe);
                      }
                      if (!Files.isWritable(path)) {
                          throw new IOException("File is not writable");
                      }
                      log.debug("Path: {}\nRead: {} write: {}", path, Files.isReadable(path), Files.isWritable(path));
                      writer = new FLVWriter(path, false);
                  } else {
                      try {
                          // delete existing file since we're not recording nor appending
                          if (Files.deleteIfExists(path)) {
                              log.debug("File deleted");
                          }
                      } catch (IOException ioe) {
                          log.error("File creation error: {}", ioe);
                      }
                  }
              } else {
                  log.warn("Consumer is uninitialized");
              }
              log.debug("Init - complete");
          }
      }
docs: Initialization
  
  @throws IOException
  I/O exception