public FileObject getFile()

in src/main/java/com/epam/digital/data/platform/user/service/FileService.java [56:80]


  public FileObject getFile(String id) {
    var cephObject = userImportCephService.get(userImportBucket, id)
        .orElseThrow(() -> new FileNotFoundException("File " + id + " not found!"));

    var base64FileName = cephObject.getMetadata().getUserMetadata().get(USER_METADATA_KEY_FILENAME);
    if (base64FileName == null) {
      throw new FileNameNotFoundException(
          "UserMetadata doesn't contain '" + USER_METADATA_KEY_FILENAME + "'. Ceph id:" + id);
    }
    
    String fileName;
    try {
      fileName = new String(Base64.getDecoder().decode(base64FileName), StandardCharsets.UTF_8);
    } catch (IllegalArgumentException ex) {
      throw new Base64DecodingException("Cannot read file name", ex);
    }
    
    byte[] content;
    try {
      content = cephObject.getContent().readAllBytes();
    } catch (IOException e) {
      throw new FileContentNotReadableException("Cannot read file content", e);
    }
    return new FileObject(id, fileName, content);
  }