class TarContainerPacker implements ContainerPacker<KeyValueContainerData> {

  @Override
  public byte[] unpackContainerData(Container<KeyValueContainerData> container,
      InputStream input)
      throws IOException {
    byte[] descriptorFileContent = null;
    KeyValueContainerData containerData = container.getContainerData();
    Path dbRoot = containerData.getDbFile().toPath();
    Path chunksRoot = Paths.get(containerData.getChunksPath());

    try (InputStream decompressed = decompress(input);
         ArchiveInputStream archiveInput = untar(decompressed)) {

      ArchiveEntry entry = archiveInput.getNextEntry();
      while (entry != null) {
        String name = entry.getName();
        long size = entry.getSize();
        if (name.startsWith(DB_DIR_NAME + "/")) {
          Path destinationPath = dbRoot
              .resolve(name.substring(DB_DIR_NAME.length() + 1));
          extractEntry(archiveInput, size, dbRoot, destinationPath);
        } else if (name.startsWith(CHUNKS_DIR_NAME + "/")) {
          Path destinationPath = chunksRoot
              .resolve(name.substring(CHUNKS_DIR_NAME.length() + 1));
          extractEntry(archiveInput, size, chunksRoot, destinationPath);
        } else if (CONTAINER_FILE_NAME.equals(name)) {
          //Don't do anything. Container file should be unpacked in a
          //separated step by unpackContainerDescriptor call.
          descriptorFileContent = readEntry(archiveInput, size);
        } else {
          throw new IllegalArgumentException(
              "Unknown entry in the tar file: " + "" + name);
        }
        entry = archiveInput.getNextEntry();
      }
      return descriptorFileContent;

    } catch (CompressorException e) {
      throw new IOException(
          "Can't uncompress the given container: " + container
              .getContainerData().getContainerID(),
          e);
    }
  }

}