Skip to content

Commit

Permalink
added checking for zero bytes while byte array saving is invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
iamironz committed Jul 14, 2017
1 parent 5183a4c commit bf0ef9d
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public final class NioFileAdapter implements FileAdapter {

private static final String[] EMPTY_STRING_NAMES_ARRAY = new String[0];

private static final String ZERO_BYTES_MESSAGE = "%s key has zero bytes for saving";
private static final String BACKUP_EXTENSION = ".bak";

private static final String R_MODE = "r";
Expand Down Expand Up @@ -93,8 +94,10 @@ public void save(String name, byte[] bytes) {
backupAndSave(name, bytes);
}

@SuppressWarnings("ResultOfMethodCallIgnored")
private void backupAndSave(String name, byte[] bytes) {
if (bytes.length == 0) {
throw new FileOperationException(String.format(ZERO_BYTES_MESSAGE, name));
}
File file = new File(baseDir, name);
File backupFile = new File(backupDir, name + BACKUP_EXTENSION);
swap(file, backupFile);
Expand Down

0 comments on commit bf0ef9d

Please sign in to comment.