Пример #1
0
  @Override
  public void writeUserProfilePhoto(long userId, MediaType ext, byte[] bytesForProfilePhoto) {

    User user = findById(userId);
    user.setProfilePhotoMediaType(ext.toString());
    user.setProfilePhotoImported(true);
    userRepository.save(user);

    ByteArrayInputStream byteArrayInputStream = null;
    FileOutputStream fileOutputStream = null;
    try {
      fileOutputStream = new FileOutputStream(fileForPhoto(userId));
      byteArrayInputStream = new ByteArrayInputStream(bytesForProfilePhoto);
      IOUtils.copy(byteArrayInputStream, fileOutputStream);
    } catch (IOException e) {
      throw new UserProfilePhotoWriteException(userId, e);
    } finally {
      IOUtils.closeQuietly(fileOutputStream);
      IOUtils.closeQuietly(byteArrayInputStream);
    }
  }