private File getOrGenerateAvatarFile(final Avatar avatar, final ImageSize size) throws IOException { final File file = getAvatarFile(avatar, size.getFilenameFlag()); //if this file doesn't exist and we requested something other than the largest size lets //try to generate a smaller image. if (!file.exists()) { File largeFile = getOrGenerateLargerAvatarFile(avatar, size); //generate a smaller image file for the avatar requested and return that! if (largeFile != null && largeFile.exists()) { return processImage(avatar, FileUtils.openInputStream(largeFile), null, size); } } return file; }