Skip to content

Commit ffb56a7

Browse files
author
Egor Martsynkovsky
committed
Add logic for checking empty files
Fix constructor PDWEB-82
1 parent 7355c13 commit ffb56a7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

commons/src/main/java/com/itextpdf/commons/utils/FileUtil.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ public static boolean fileExists(String path) {
110110
return false;
111111
}
112112

113+
/**
114+
* Checks whether is provided file not empty.
115+
*
116+
* @param path the path to the file to be checked on emptiness
117+
*
118+
* @return {@code true} if such file is not empty, {@code false} otherwise
119+
*/
120+
public static boolean isFileNotEmpty(String path) {
121+
if (path != null) {
122+
File f = new File(path);
123+
return f.exists() && f.isFile() && f.length() > 0;
124+
}
125+
return false;
126+
}
127+
113128
/**
114129
* Checks whether there is a directory at the provided path.
115130
*

commons/src/main/java/com/itextpdf/commons/utils/ZipFileWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public ZipFileWriter(String archivePath) throws IOException {
5151
if (archivePath == null) {
5252
throw new IOException(CommonsExceptionMessageConstant.FILE_NAME_CAN_NOT_BE_NULL);
5353
}
54-
if (FileUtil.fileExists(archivePath) || FileUtil.directoryExists(archivePath)) {
54+
if (FileUtil.isFileNotEmpty(archivePath) || FileUtil.directoryExists(archivePath)) {
5555
throw new IOException(
5656
MessageFormatUtil.format(CommonsExceptionMessageConstant.FILE_NAME_ALREADY_EXIST, archivePath));
5757
}

0 commit comments

Comments
 (0)