Skip to content

Commit

Permalink
Don't evaluate the whole content to detect if it is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Nov 19, 2024
1 parent 317e862 commit 1e136b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,17 @@ private File extractFile(File destinationDirectory, ZipEntry zipEntry, InputStre
}
return file;
}

@Override
public boolean hasContainerContents(File file) {

try (ZipFile zipFile = new ZipFile(file)) {
return zipFile.entries().hasMoreElements();
} catch(ZipException e) {
logger.warn(e);
} catch(IOException e) {
logger.warn(e);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

public interface IFileContentProvider {

public boolean hasContainerContents(File container);

public long getContentSize(File container);

public File[] getContents(File container);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Lablicate GmbH.
* Copyright (c) 2019, 2024 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -189,7 +189,7 @@ private File[] unfoldDirectories(File[] childs) {
private boolean hasContainerContents(File file) {

IFileContentProvider fileContentProvider = FileContainerSupport.getCache().getFileContentProvider(file);
return fileContentProvider != null && fileContentProvider.getContentSize(file) > 0;
return fileContentProvider != null && fileContentProvider.hasContainerContents(file);
}

private File[] getContainerContents(File file) {
Expand Down

0 comments on commit 1e136b5

Please sign in to comment.