/** * Returns a string representing the internal values of this <code>Thumbnail</code> object. This string contains the * MIME Media type, width and height of this <code>Thumbnail</code> object. * * @return a string representation of this <code>Thumbnail</code> object */ @Override public String toString() { return getClass().getName() + " [MimeType=" + mimeType + ",width=" + getWidth() + ",height=" + getHeight() + ",filename=" + getFilename() + ",attachmentId=" + getAttachmentId() + "]"; } }
return new Thumbnail(thumbnail.getHeight(), thumbnail.getWidth(), thumbnailFile.getName(), attachment.getId(), thumbnail.getMimeType());
public ThumbnailItem apply(Thumbnail thumbnail) { if (thumbnail.getFilename() == null) { return brokenThumbnailItem(attachment, baseUri); } return new ThumbnailItem( uriProvider.getThumbnailUri(baseUri, thumbnail), uriProvider.getAttachmentUri(baseUri, attachment), scaleToThumbnailSize(thumbnail.getWidth(), thumbnail.getHeight())); } };
public URI getThumbnailUri(URI baseUri, Thumbnail thumbnail) { return URI.create(baseUri.toASCIIString() + "/secure/thumbnail/" + thumbnail.getAttachmentId() + "/" + Uris.encode(thumbnail.getFilename())); }
private Thumbnail getThumbnail(File thumbnailFile, String filename, long thumbId) throws IOException { if (thumbnailFile.exists()) { final Image thumbImage = getImage(thumbnailFile, Predicates.<ReusableBufferedInputStream>alwaysTrue()); return new Thumbnail(thumbImage.getHeight(null), thumbImage.getWidth(null), filename, thumbId, mimeType); } return null; }
@Override public int getHeight() { return thumbnail.getHeight(); }
@Override public int getWidth() { return thumbnail.getWidth(); }
@Override public String getFilename() { return thumbnail.getFilename(); }
@Override public long getAttachmentId() { return thumbnail.getAttachmentId(); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } AttachmentItem that = (AttachmentItem) o; if (!attachment.equals(that.attachment)) { return false; } if (thumbnail != null ? !thumbnail.equals(that.thumbnail) : that.thumbnail != null) { return false; } return true; }
@Override public String getMimeType() { return thumbnail.getMimeType().name(); }
@Override @HtmlSafe public String getImageURL() { if (thumbnail == null) { return null; } if (thumbnail instanceof BrokenThumbnail) { return velocityRequestContext.getCanonicalBaseUrl() + BROKEN_THUMBNAIL_URL; } return String.format("%s/secure/thumbnail/%s/%s", velocityRequestContext.getCanonicalBaseUrl(), thumbnail.getAttachmentId(), urlEncode(thumbnail.getFilename())); }
private Thumbnail getThumbnail(File thumbnailFile, String filename, long thumbId) throws IOException { if (thumbnailFile.exists()) { final Image thumbImage = getImage(thumbnailFile); return new Thumbnail(thumbImage.getHeight(null), thumbImage.getWidth(null), filename, thumbId); } return null; }
private Thumbnail createThumbnail(InputStream inputStream, File thumbnailFile, int maxWidth, int maxHeight, long thumbId, String fileName) throws IOException, ThumbnailRenderException { final BufferedImage thumbnailImage = scaleImage(maxWidth, maxHeight, inputStream); final int height = thumbnailImage.getHeight(); final int width = thumbnailImage.getWidth(); storeImage(thumbnailImage, thumbnailFile); return new Thumbnail(height, width, fileName, thumbId, mimeType); }
private Thumbnail createThumbnail(InputStream originalFile, File thumbnailFile, int maxWidth, int maxHeight, long thumbId, String fileName) throws IOException, FileNotFoundException { // Load original image. Image originalImage = getImage(originalFile); // Create scaled buffered image from original image. BufferedImage scaledImage = scaleImage(originalImage, maxWidth, maxHeight); int height = scaledImage.getHeight(); int width = scaledImage.getWidth(); storeImage(scaledImage, thumbnailFile); return new Thumbnail(height, width, fileName, thumbId); }
private Thumbnail readThumbnail(@Nonnull final Attachment attachment, @Nonnull final File thumbnailFile) { if (thumbnailFile.exists()) { log.debug("Thumbnail file '{}' already exists. Returning existing thumbnail.", thumbnailFile); InputStream inputStream = null; try { inputStream = new FileInputStream(thumbnailFile); final ThumbnailDimension thumbnailDimension = ThumbnailUtil.dimensionsForImage(inputStream); return new Thumbnail(thumbnailDimension.getHeight(), thumbnailDimension.getWidth(), thumbnailFile.getName(), attachment.getId(), MIME_TYPE); } catch (IOException asd) { log.debug("Unable to read image data from existing thumbnail file '{}'. Deleting this thumbnail.", thumbnailFile); deleteQuietly(thumbnailFile); } finally { closeQuietly(inputStream); } } return null; }