dir: add methods getSize() and getCompressedSize()

This commit is contained in:
Alexei Khlebnikov 2018-07-19 18:12:07 +02:00
parent eecfc18c82
commit 76bf6ff0c8
3 changed files with 42 additions and 2 deletions

View File

@ -47,6 +47,10 @@ public interface Directory {
public void copyToDir(File out, String fileName)
throws DirectoryException;
public long getSize(String fileName)
throws DirectoryException;
public long getCompressedSize(String fileName)
throws DirectoryException;
public int getCompressionLevel(String fileName)
throws DirectoryException;

View File

@ -40,6 +40,22 @@ public class FileDirectory extends AbstractDirectory {
mDir = dir;
}
@Override
public long getSize(String fileName)
throws DirectoryException {
File file = new File(generatePath(fileName));
if (! file.isFile()) {
throw new DirectoryException("file must be a file: " + file);
}
return file.length();
}
@Override
public long getCompressedSize(String fileName)
throws DirectoryException {
return getSize(fileName);
}
@Override
protected AbstractDirectory createDirLocal(String name) throws DirectoryException {
File dir = new File(generatePath(name));

View File

@ -100,14 +100,34 @@ public class ZipRODirectory extends AbstractDirectory {
throw new UnsupportedOperationException();
}
@Override
public long getSize(String fileName)
throws DirectoryException {
ZipEntry entry = getZipFileEntry(fileName);
return entry.getSize();
}
@Override
public long getCompressedSize(String fileName)
throws DirectoryException {
ZipEntry entry = getZipFileEntry(fileName);
return entry.getCompressedSize();
}
@Override
public int getCompressionLevel(String fileName)
throws DirectoryException {
ZipEntry entry = mZipFile.getEntry(fileName);
ZipEntry entry = getZipFileEntry(fileName);
return entry.getMethod();
}
private ZipEntry getZipFileEntry(String fileName)
throws DirectoryException {
ZipEntry entry = mZipFile.getEntry(fileName);
if (entry == null) {
throw new PathNotExist("Entry not found: " + fileName);
}
return entry.getMethod();
return entry;
}
private void loadAll() {