public synchronized boolean serializeToFile(final File snapshotName) throws IOException {
    final File snapshotFile = new File(String.valueOf(snapshotName));
    if (snapshotFile.exists() && snapshotFile.isFile()) {
      LOGGER.warn(
          "Failed to serialize to file, because file {} is already exist.",
          snapshotFile.getAbsolutePath());
      return false;
    }

    try (final FileOutputStream fileOutputStream = new FileOutputStream(snapshotFile)) {
      ReadWriteIOUtils.write(isClosed.get(), fileOutputStream);
      ReadWriteIOUtils.write(serializerType.getType(), fileOutputStream);
      if (serializers.containsKey(serializerType)) {
        return serializers
            .get(serializerType)
            .get()
            .writeQueueToFile(fileOutputStream, queue, this::serializeToByteBuffer);
      } else {
        throw new UnsupportedOperationException(
            "Unknown serializer type: " + serializerType.getType());
      }
    }
  }
{@link AbstractSerializableListeningQueue} is the encapsulation of the {@link
ConcurrentIterableLinkedQueue} to enable flushing all the element to disk and reading from it. To
implement this, each element much be configured with its own ser/de method. Besides, this class
also provides a means of opening and closing the queue, and a queue will stay empty while closed.
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/datastructure/queue/listening/AbstractSerializableListeningQueue.java