@Test(expected=Exception.class) public void test_ThumbnailGeneration_Fail_Audio() throws Exception { final Integer width = ThumbnailType.LARGE.getWidth(); final Integer height = ThumbnailType.LARGE.getHeight(); final MediaFile thumbnail = ThumbnailGeneratorFactory.getThumbnailGenerator(ContentType.AUDIO, PATH_COLORMAP) .createMediaFileWithThumbnail(height, width, "", getPath(Audio2), filesInBytes.get(Audio2), getPath(Audio2)); assertNull(thumbnail); }
public MediaFile createMediaFileWithThumbnail (final Integer expectedWidth, final Integer expectedHeight, final String currentProcessId, final String originalFileUrl, final byte[] originalFileContent, final String originalFilePath) throws Exception { final ImageInfo originalFileInfo = MediaChecker.getImageInfo(originalFilePath, getColorMapPath()); Integer thumbnailResizedToWidth = null; Integer thumbnailResizedToHeight = null; if (expectedWidth != ThumbnailType.MEDIUM.getWidth() && expectedWidth != ThumbnailType.LARGE.getWidth()) { throw new IllegalArgumentException("Cannot generate thumbnails from configuration tasks where width != "+ThumbnailType.MEDIUM.getHeight() + " or width != "+ThumbnailType.LARGE.getHeight()); } if (expectedWidth == ThumbnailType.MEDIUM.getWidth()) { if (originalFileInfo.getWidth() < ThumbnailType.MEDIUM.getWidth()) { thumbnailResizedToWidth = null; thumbnailResizedToHeight = null; } else { thumbnailResizedToWidth = ThumbnailType.MEDIUM.getWidth(); thumbnailResizedToHeight = null; } } if (expectedWidth == ThumbnailType.LARGE.getWidth()) { if (originalFileInfo.getWidth() < ThumbnailType.LARGE.getWidth()) { thumbnailResizedToWidth = null; thumbnailResizedToHeight = null; } else { thumbnailResizedToWidth = ThumbnailType.LARGE.getWidth(); thumbnailResizedToHeight = null; } } final String url = originalFileUrl; final String[] temp = url.split("/"); String name = url; if (temp.length > 0) { name = temp[temp.length - 1]; } final byte[] newData = createThumbnail(new ByteArrayInputStream(originalFileContent), thumbnailResizedToWidth, thumbnailResizedToHeight, originalFileContent); final ThumbnailType expectedThumbnailType = thumbnailTypeFromExpectedSize(expectedHeight, expectedWidth); if (expectedThumbnailType == null) throw new IllegalArgumentException("The expected thumbnail height "+expectedHeight+" or width "+expectedWidth+" do not match any of the hardcoded presets"); return new MediaFile(currentProcessId, name, null, null, url, new DateTime(System.currentTimeMillis()), newData, 1, MediaChecker.getMimeType(originalFilePath), null, newData.length) .withId(MediaFile.generateIdFromUrlAndSizeType(originalFileUrl, expectedThumbnailType.name())); }
ThumbnailGenerator { public MediaFile createMediaFileWithThumbnail (final Integer expectedWidth, final Integer expectedHeight, final String currentProcessId, final String originalFileUrl, final byte[] originalFileContent, final String originalFilePath) throws Exception { final ImageInfo originalFileInfo = MediaChecker.getImageInfo(originalFilePath, getColorMapPath()); Integer thumbnailResizedToWidth = null; Integer thumbnailResizedToHeight = null; if (expectedWidth != ThumbnailType.MEDIUM.getWidth() && expectedWidth != ThumbnailType.LARGE.getWidth()) { throw new IllegalArgumentException("Cannot generate thumbnails from configuration tasks where width != "+ThumbnailType.MEDIUM.getHeight() + " or width != "+ThumbnailType.LARGE.getHeight()); } if (expectedWidth == ThumbnailType.MEDIUM.getWidth()) { if (originalFileInfo.getWidth() < ThumbnailType.MEDIUM.getWidth()) { thumbnailResizedToWidth = null; thumbnailResizedToHeight = null; } else { thumbnailResizedToWidth = ThumbnailType.MEDIUM.getWidth(); thumbnailResizedToHeight = null; } } if (expectedWidth == ThumbnailType.LARGE.getWidth()) { if (originalFileInfo.getWidth() < ThumbnailType.LARGE.getWidth()) { thumbnailResizedToWidth = null; thumbnailResizedToHeight = null; } else { thumbnailResizedToWidth = ThumbnailType.LARGE.getWidth(); thumbnailResizedToHeight = null; } } final String url = originalFileUrl; final String[] temp = url.split("/"); String name = url; if (temp.length > 0) { name = temp[temp.length - 1]; } final byte[] newData = createThumbnail(new ByteArrayInputStream(originalFileContent), thumbnailResizedToWidth, thumbnailResizedToHeight, originalFileContent); final ThumbnailType expectedThumbnailType = thumbnailTypeFromExpectedSize(expectedHeight, expectedWidth); if (expectedThumbnailType == null) throw new IllegalArgumentException("The expected thumbnail height "+expectedHeight+" or width "+expectedWidth+" do not match any of the hardcoded presets"); return new MediaFile(currentProcessId, name, null, null, url, new DateTime(System.currentTimeMillis()), newData, 1, MediaChecker.getMimeType(originalFilePath), null, newData.length) .withId(MediaFile.generateIdFromUrlAndSizeType(originalFileUrl, expectedThumbnailType.name())); } }
ThumbnailGenerator { public MediaFile createMediaFileWithThumbnail (final Integer expectedWidth, final Integer expectedHeight, final String currentProcessId, final String originalFileUrl, final byte[] originalFileContent, final String originalFilePath) throws Exception { final ImageInfo originalFileInfo = MediaChecker.getImageInfo(originalFilePath, getColorMapPath()); Integer thumbnailResizedToWidth = null; Integer thumbnailResizedToHeight = null; if (expectedWidth != ThumbnailType.MEDIUM.getWidth() && expectedWidth != ThumbnailType.LARGE.getWidth()) { throw new IllegalArgumentException("Cannot generate thumbnails from configuration tasks where width != "+ThumbnailType.MEDIUM.getHeight() + " or width != "+ThumbnailType.LARGE.getHeight()); } if (expectedWidth == ThumbnailType.MEDIUM.getWidth()) { if (originalFileInfo.getWidth() < ThumbnailType.MEDIUM.getWidth()) { thumbnailResizedToWidth = null; thumbnailResizedToHeight = null; } else { thumbnailResizedToWidth = ThumbnailType.MEDIUM.getWidth(); thumbnailResizedToHeight = null; } } if (expectedWidth == ThumbnailType.LARGE.getWidth()) { if (originalFileInfo.getWidth() < ThumbnailType.LARGE.getWidth()) { thumbnailResizedToWidth = null; thumbnailResizedToHeight = null; } else { thumbnailResizedToWidth = ThumbnailType.LARGE.getWidth(); thumbnailResizedToHeight = null; } } final String url = originalFileUrl; final String[] temp = url.split("/"); String name = url; if (temp.length > 0) { name = temp[temp.length - 1]; } final byte[] newData = createThumbnail(new ByteArrayInputStream(originalFileContent), thumbnailResizedToWidth, thumbnailResizedToHeight, originalFileContent); final ThumbnailType expectedThumbnailType = thumbnailTypeFromExpectedSize(expectedHeight, expectedWidth); if (expectedThumbnailType == null) throw new IllegalArgumentException("The expected thumbnail height "+expectedHeight+" or width "+expectedWidth+" do not match any of the hardcoded presets"); return new MediaFile(currentProcessId, name, null, null, url, new DateTime(System.currentTimeMillis()), newData, 1, MediaChecker.getMimeType(originalFilePath), null, newData.length) .withId(MediaFile.generateIdFromUrlAndSizeType(originalFileUrl, expectedThumbnailType.name())); } ThumbnailGenerator(String colorMapPath); }
ThumbnailGenerator { public MediaFile createMediaFileWithThumbnail (final Integer expectedWidth, final Integer expectedHeight, final String currentProcessId, final String originalFileUrl, final byte[] originalFileContent, final String originalFilePath) throws Exception { final ImageInfo originalFileInfo = MediaChecker.getImageInfo(originalFilePath, getColorMapPath()); Integer thumbnailResizedToWidth = null; Integer thumbnailResizedToHeight = null; if (expectedWidth != ThumbnailType.MEDIUM.getWidth() && expectedWidth != ThumbnailType.LARGE.getWidth()) { throw new IllegalArgumentException("Cannot generate thumbnails from configuration tasks where width != "+ThumbnailType.MEDIUM.getHeight() + " or width != "+ThumbnailType.LARGE.getHeight()); } if (expectedWidth == ThumbnailType.MEDIUM.getWidth()) { if (originalFileInfo.getWidth() < ThumbnailType.MEDIUM.getWidth()) { thumbnailResizedToWidth = null; thumbnailResizedToHeight = null; } else { thumbnailResizedToWidth = ThumbnailType.MEDIUM.getWidth(); thumbnailResizedToHeight = null; } } if (expectedWidth == ThumbnailType.LARGE.getWidth()) { if (originalFileInfo.getWidth() < ThumbnailType.LARGE.getWidth()) { thumbnailResizedToWidth = null; thumbnailResizedToHeight = null; } else { thumbnailResizedToWidth = ThumbnailType.LARGE.getWidth(); thumbnailResizedToHeight = null; } } final String url = originalFileUrl; final String[] temp = url.split("/"); String name = url; if (temp.length > 0) { name = temp[temp.length - 1]; } final byte[] newData = createThumbnail(new ByteArrayInputStream(originalFileContent), thumbnailResizedToWidth, thumbnailResizedToHeight, originalFileContent); final ThumbnailType expectedThumbnailType = thumbnailTypeFromExpectedSize(expectedHeight, expectedWidth); if (expectedThumbnailType == null) throw new IllegalArgumentException("The expected thumbnail height "+expectedHeight+" or width "+expectedWidth+" do not match any of the hardcoded presets"); return new MediaFile(currentProcessId, name, null, null, url, new DateTime(System.currentTimeMillis()), newData, 1, MediaChecker.getMimeType(originalFilePath), null, newData.length) .withId(MediaFile.generateIdFromUrlAndSizeType(originalFileUrl, expectedThumbnailType.name())); } ThumbnailGenerator(String colorMapPath); MediaFile createMediaFileWithThumbnail(final Integer expectedWidth, final Integer expectedHeight, final String currentProcessId, final String originalFileUrl, final byte[] originalFileContent, final String originalFilePath); String getColorMapPath(); }
ThumbnailGenerator { public MediaFile createMediaFileWithThumbnail (final Integer expectedWidth, final Integer expectedHeight, final String currentProcessId, final String originalFileUrl, final byte[] originalFileContent, final String originalFilePath) throws Exception { final ImageInfo originalFileInfo = MediaChecker.getImageInfo(originalFilePath, getColorMapPath()); Integer thumbnailResizedToWidth = null; Integer thumbnailResizedToHeight = null; if (expectedWidth != ThumbnailType.MEDIUM.getWidth() && expectedWidth != ThumbnailType.LARGE.getWidth()) { throw new IllegalArgumentException("Cannot generate thumbnails from configuration tasks where width != "+ThumbnailType.MEDIUM.getHeight() + " or width != "+ThumbnailType.LARGE.getHeight()); } if (expectedWidth == ThumbnailType.MEDIUM.getWidth()) { if (originalFileInfo.getWidth() < ThumbnailType.MEDIUM.getWidth()) { thumbnailResizedToWidth = null; thumbnailResizedToHeight = null; } else { thumbnailResizedToWidth = ThumbnailType.MEDIUM.getWidth(); thumbnailResizedToHeight = null; } } if (expectedWidth == ThumbnailType.LARGE.getWidth()) { if (originalFileInfo.getWidth() < ThumbnailType.LARGE.getWidth()) { thumbnailResizedToWidth = null; thumbnailResizedToHeight = null; } else { thumbnailResizedToWidth = ThumbnailType.LARGE.getWidth(); thumbnailResizedToHeight = null; } } final String url = originalFileUrl; final String[] temp = url.split("/"); String name = url; if (temp.length > 0) { name = temp[temp.length - 1]; } final byte[] newData = createThumbnail(new ByteArrayInputStream(originalFileContent), thumbnailResizedToWidth, thumbnailResizedToHeight, originalFileContent); final ThumbnailType expectedThumbnailType = thumbnailTypeFromExpectedSize(expectedHeight, expectedWidth); if (expectedThumbnailType == null) throw new IllegalArgumentException("The expected thumbnail height "+expectedHeight+" or width "+expectedWidth+" do not match any of the hardcoded presets"); return new MediaFile(currentProcessId, name, null, null, url, new DateTime(System.currentTimeMillis()), newData, 1, MediaChecker.getMimeType(originalFilePath), null, newData.length) .withId(MediaFile.generateIdFromUrlAndSizeType(originalFileUrl, expectedThumbnailType.name())); } ThumbnailGenerator(String colorMapPath); MediaFile createMediaFileWithThumbnail(final Integer expectedWidth, final Integer expectedHeight, final String currentProcessId, final String originalFileUrl, final byte[] originalFileContent, final String originalFilePath); String getColorMapPath();  }