private void verifyExists() throws FileNotFoundException { if (!exists()) { throw new FileNotFoundException(String.format("%s does not exist.", getDescription())); } } }
/** * Returns the {@link Resource}'s id. * * @return never {@literal null}. * @throws IllegalStateException if the file does not {@link #exists()}. */ public Object getId() { Assert.state(exists(), () -> String.format("%s does not exist.", getDescription())); return file.getId(); }
/** * Returns the {@link Resource}'s content type. * * @return never {@literal null}. * @throws com.mongodb.MongoGridFSException in case no content type declared on {@link GridFSFile#getMetadata()} nor * provided via {@link GridFSFile#getContentType()}. * @throws IllegalStateException if the file does not {@link #exists()}. */ @SuppressWarnings("deprecation") public String getContentType() { Assert.state(exists(), () -> String.format("%s does not exist.", getDescription())); return Optionals .firstNonEmpty( () -> Optional.ofNullable(file.getMetadata()).map(it -> it.get(CONTENT_TYPE_FIELD, String.class)), () -> Optional.ofNullable(file.getContentType())) .orElseThrow(() -> new MongoGridFSException("No contentType data for this GridFS file")); }
private void verifyExists() throws FileNotFoundException { if (!exists()) { throw new FileNotFoundException(String.format("%s does not exist.", getDescription())); } } }
/** * Returns the {@link Resource}'s id. * * @return never {@literal null}. * @throws IllegalStateException if the file does not {@link #exists()}. */ public Object getId() { Assert.state(exists(), () -> String.format("%s does not exist.", getDescription())); return file.getId(); }
/** * Returns the {@link Resource}'s content type. * * @return never {@literal null}. * @throws com.mongodb.MongoGridFSException in case no content type declared on {@link GridFSFile#getMetadata()} nor * provided via {@link GridFSFile#getContentType()}. * @throws IllegalStateException if the file does not {@link #exists()}. */ @SuppressWarnings("deprecation") public String getContentType() { Assert.state(exists(), () -> String.format("%s does not exist.", getDescription())); return Optionals .firstNonEmpty( () -> Optional.ofNullable(file.getMetadata()).map(it -> it.get(CONTENT_TYPE_FIELD, String.class)), () -> Optional.ofNullable(file.getContentType())) .orElseThrow(() -> new MongoGridFSException("No contentType data for this GridFS file")); }