class StorageFileHelper {

    StorageFile createStorageFileFromEntity(StorageFileEntity storageFileEntity, String storageUnitDirectoryPath)
    {
        // Get storage file path from the entity.
        String storageFilePath = storageFileEntity.getPath();

        // If storage directory path is specified, prepend it to the storage file path, if not already there.
        if (StringUtils.isNotBlank(storageUnitDirectoryPath))
        {
            // If storage file path does not start with storage unit directory path:
            // - For the empty folder S3 marker prepend storage unit directory path as is
            // - For all other storage files, prepend storage unit directory path with slash
            if (!StringUtils.startsWith(storageFilePath, storageUnitDirectoryPath))
            {
                if (StringUtils.equals(storageFilePath, StorageFileEntity.S3_EMPTY_PARTITION))
                {
                    storageFilePath = storageUnitDirectoryPath + storageFilePath;
                }
                else
                {
                    storageFilePath = StringUtils.appendIfMissing(storageUnitDirectoryPath, "/") + storageFilePath;
                }
            }
        }

        // Create and return storage file.
        return new StorageFile(storageFilePath, storageFileEntity.getFileSizeBytes(), storageFileEntity.getRowCount());
    }

}