class ContainerDataYaml {

  public static void createContainerFile(ContainerType containerType,
      ContainerData containerData, File containerFile) throws IOException {
    Writer writer = null;
    FileOutputStream out = null;
    try {
      // Create Yaml for given container type
      Yaml yaml = getYamlForContainerType(containerType);
      // Compute Checksum and update ContainerData
      containerData.computeAndSetChecksum(yaml);

      // Write the ContainerData with checksum to Yaml file.
      out = new FileOutputStream(
          containerFile);
      writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
      yaml.dump(containerData, writer);
    } finally {
      try {
        if (writer != null) {
          writer.flush();
          // make sure the container metadata is synced to disk.
          out.getFD().sync();
          writer.close();
        }
      } catch (IOException ex) {
        LOG.warn("Error occurred during closing the writer. ContainerID: " +
            containerData.getContainerID());
      }
      IOUtils.closeQuietly(out);
    }
  }

  private  ContainerDataYaml();

}