@Override
 public void endPutFile(String path, SsNormalFileDto fromNormalFileDto) {
   putPaddingMetaData(path, fromNormalFileDto);
   super.endPutFile(
       path,
       fromNormalFileDto.getLastModified(),
       fromNormalFileDto.getLength(),
       fromNormalFileDto.getSha1());
 }
  private void putPaddingMetaData(String path, SsNormalFileDto fromNormalFileDto) {
    path = prefixPath(path); // does a null-check
    assertNotNull("fromNormalFileDto", fromNormalFileDto);

    final File file = getFile(path);
    try (final LocalRepoTransaction transaction = getLocalRepoManager().beginWriteTransaction(); ) {
      final RepoFile repoFile =
          transaction
              .getDao(RepoFileDao.class)
              .getRepoFile(getLocalRepoManager().getLocalRoot(), file);
      if (!(repoFile instanceof NormalFile)) {
        throw new IllegalStateException(
            String.format(
                "RepoFile is not an instance of NormalFile! repoFile=%s file=%s", repoFile, file));
      }

      final SsNormalFile normalFile = (SsNormalFile) repoFile;
      normalFile.setLengthWithPadding(fromNormalFileDto.getLengthWithPadding());

      final Map<Long, SsFileChunk> offset2FileChunk =
          new HashMap<>(normalFile.getFileChunks().size());
      for (FileChunk fc : normalFile.getFileChunks())
        offset2FileChunk.put(fc.getOffset(), (SsFileChunk) fc);

      for (final FileChunkDto fcDto : fromNormalFileDto.getFileChunkDtos()) {
        SsFileChunkDto fileChunkDto = (SsFileChunkDto) fcDto;

        // If there is at least 1 byte of real data, the SHA1 (as well as the entire FileChunk
        // object)
        // is created from it and we don't need to store the FileChunk we received from the other
        // side.
        if (fileChunkDto.getLength() > 0) continue;

        boolean isNew = false;
        SsFileChunk fileChunk = offset2FileChunk.get(fileChunkDto.getOffset());
        if (fileChunk == null) {
          isNew = true;
          fileChunk = (SsFileChunk) createObject(FileChunk.class);
          fileChunk.setNormalFile(normalFile);
          fileChunk.setOffset(fileChunkDto.getOffset());
        }
        fileChunk.makeWritable();
        fileChunk.setLength(fileChunkDto.getLength());
        fileChunk.setLengthWithPadding(fileChunkDto.getLengthWithPadding());
        fileChunk.setSha1(fileChunkDto.getSha1());
        fileChunk.makeReadOnly();

        if (isNew) normalFile.getFileChunks().add(fileChunk);
      }

      transaction.commit();
    }
  }