code: @SuppressWarnings("ConstantConditions")
      @Override
      public void storeSnapshot(ExtendedSnapshotWriter snapshotWriter) throws StorageException {
          checkInitialized();
  
          checkArgument(snapshotWriter instanceof SnapshotFileWriter, "unknown snapshot request type:%s", snapshotWriter.getClass().getSimpleName());
  
          final SnapshotFileWriter snapshotFileWriter = (SnapshotFileWriter) snapshotWriter;
          checkArgument(snapshotFileWriter.snapshotStarted(), "snapshot was never started");
  
          try {
              // first close the output stream (the snapshotFileWriter may already have done this, but nbd)
              snapshotFileWriter.getSnapshotOutputStream().close();
  
              // the time we'll assign to this snapshot (both in the filename and the db)
              long snapshotTimestamp = System.currentTimeMillis();
  
              // setup the name/path of the final snapshot file
              String snapshotFilename = String.format("%d-%s.snap", snapshotTimestamp, UUID.randomUUID().toString());
              File snapshotFile = new File(snapshotsDirectory, snapshotFilename);
  
              // move the temporary file to the final location
              File tempSnapshotFile = snapshotFileWriter.getSnapshotFile();
              Files.move(tempSnapshotFile.toPath(), snapshotFile.toPath(), StandardCopyOption.ATOMIC_MOVE);
  
              // create the metadata entry for this snapshot
              // note that this filename does _not_ include the path, only the filename itself
              final SnapshotMetadata metadata = new SnapshotMetadata(
                              snapshotFilename,
                              snapshotTimestamp,
                              snapshotFileWriter.getTerm(),
                              snapshotFileWriter.getIndex());
  
              // actually add this snapshot to the db
              dbi.withHandle(new HandleCallback<Void>() {
                  @Override
                  public Void withHandle(Handle handle) throws Exception {
                      SnapshotsDAO dao = handle.attach(SnapshotsDAO.class);
                      dao.addSnapshot(metadata);
                      return null;
                  }
              });
          } catch (IOException e) {
              throw new StorageException("fail finalize snapshot file req:" + snapshotFileWriter, e);
          } catch (CallbackFailedException e) {
              throw new StorageException("fail store snapshot metadata req:" + snapshotFileWriter, e.getCause());
          } catch (Exception e) {
              throw new StorageException("fail store snapshot req:" + snapshotFileWriter, e);
          }
      }
docs: {@inheritDoc}
  
  @throws IllegalStateException if this method is called before {@link OnDiskSnapshotsStore#initialize()}