Minor optimizations and more talking logs messages
This commit is contained in:
parent
efea30e5e5
commit
157e5f46aa
|
@ -38,15 +38,17 @@ public class FileAvatarStorageProvider implements AvatarStorageProvider {
|
|||
public void saveAvatarImage(RealmModel realm, UserModel user, InputStream input) {
|
||||
checkRealmFolderExistence(realm.getName());
|
||||
File avatarFile = getAvatarFile(realm, user);
|
||||
logger.debugf("Saving new avatar file for user %s, file path is: %s", user.getUsername(),
|
||||
avatarFile.getAbsolutePath());
|
||||
|
||||
if (!avatarFile.exists()) {
|
||||
logger.debugf("Saving new avatar file for user %s, file path is: %s", user.getUsername(),
|
||||
avatarFile.getAbsolutePath());
|
||||
try {
|
||||
avatarFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
logger.error("Cannot create new avater file", e);
|
||||
}
|
||||
} else {
|
||||
logger.debugf("Overwriting avatar file with new image for user %s, file path is: %s", user.getUsername(),
|
||||
avatarFile.getAbsolutePath());
|
||||
}
|
||||
try (FileOutputStream fos = new FileOutputStream(avatarFile)) {
|
||||
IOUtils.copy(input, fos);
|
||||
|
@ -58,7 +60,7 @@ public class FileAvatarStorageProvider implements AvatarStorageProvider {
|
|||
private void checkRealmFolderExistence(String realmName) {
|
||||
File realmFile = new File(avatarFolder, realmName);
|
||||
if (!realmFile.exists()) {
|
||||
logger.infof("Creating avatar folder for realm '%s' in %s", realmName, realmFile.getAbsolutePath());
|
||||
logger.infof("Creating avatar folder for realm '%s' as %s", realmName, realmFile.getAbsolutePath());
|
||||
realmFile.mkdir();
|
||||
}
|
||||
}
|
||||
|
@ -66,15 +68,8 @@ public class FileAvatarStorageProvider implements AvatarStorageProvider {
|
|||
@Override
|
||||
public InputStream loadAvatarImage(RealmModel realm, UserModel user) {
|
||||
checkRealmFolderExistence(realm.getName());
|
||||
File avatarFile = getAvatarFile(realm, user);
|
||||
if (avatarFile.exists()) {
|
||||
logger.debugf("Loading avatar file for user %s, file path is: %s", user.getUsername(),
|
||||
avatarFile.getAbsolutePath());
|
||||
} else {
|
||||
logger.debugf("Avatar file not found for user %s", user.getUsername());
|
||||
}
|
||||
try {
|
||||
return new FileInputStream(avatarFile);
|
||||
return new FileInputStream(getAvatarFile(realm, user));
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.debugf("Avatar file not found for user '%s' in realm '%s'", user.getUsername(), realm.getName());
|
||||
return null;
|
||||
|
@ -91,12 +86,12 @@ public class FileAvatarStorageProvider implements AvatarStorageProvider {
|
|||
checkRealmFolderExistence(realm.getName());
|
||||
File avatarFile = getAvatarFile(realm, user);
|
||||
if (avatarFile.exists()) {
|
||||
logger.debugf("Deleting avatar file for user %s, file path is: %s", user.getUsername(),
|
||||
avatarFile.getAbsolutePath());
|
||||
logger.debugf("Deleting avatar file for user '%s' in realm '%s', file path is: %s", user.getUsername(),
|
||||
realm.getName(), avatarFile.getAbsolutePath());
|
||||
|
||||
avatarFile.delete();
|
||||
} else {
|
||||
logger.debugf("Avatar file to delete not found for user %s", user.getUsername());
|
||||
logger.debugf("Avatar file to delete not found for user '%s' in realm '%s'", user.getUsername(), realm.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue