Java Utililty Methods Zip File Check

List of utility methods to do Zip File Check

Description

The list of methods to do Zip File Check are organized into topic(s).

Method

booleanisZip(BufferedInputStream in)
Test for ZIP stream signature.
in.mark(4);
byte[] b = new byte[4];
byte[] zipSig = new byte[4];
zipSig[0] = 0x50;
zipSig[1] = 0x4b;
zipSig[2] = 0x03;
zipSig[3] = 0x04;
try {
...
booleanisZip(byte[] bytes)
is Zip
return Byte.compare(bytes[0], (byte) 0x50) == 0 && Byte.compare(bytes[1], (byte) 0x4B) == 0;
booleanisZip(File candidate)
Checks if is zip (extension == zip).
return candidate.getName().toLowerCase().endsWith(".zip");
booleanisZip(File f)
is Zip
return f.getName().endsWith(".zip");
booleanisZip(File file)
is Zip
return existsWithExtension(file, ".zip");
booleanisZip(File file)
is Zip
try (FileInputStream inputStream = new FileInputStream(file)) {
    return new ZipInputStream(inputStream).getNextEntry() != null;
} catch (IOException e) {
    throw new RuntimeException("Problem to check if file " + file.getPath() + " is a zip", e);
booleanisZip(File file)
is Zip
if (file.isDirectory()) {
    return false;
if (!file.canRead()) {
    return false;
if (file.length() < 4) {
    return false;
...
booleanisZip(File file)
is Zip
if (file.exists() == false)
    return false;
try (InputStream in = new FileInputStream(file); ZipInputStream zipIn = new ZipInputStream(in)) {
    ZipEntry e = zipIn.getNextEntry();
    if (e == null)
        return false;
    int ctr = 0;
    while (e != null && ctr < 4) {
...
booleanisZip(File zip)
Check to see if the file is a zip file.

The ZIP file format can be determined by detecting #MAGIC_BYTES at the start of the zip file.
byte[] buffer = new byte[MAGIC_BYTES.length];
if (zip == null)
    throw new NullPointerException("Zip file is null");
assert zip != null;
if (zip.isDirectory())
    return false;
InputStream in = new DataInputStream(new FileInputStream(zip));
in.read(buffer);
...
booleanisZip64EndOfCentralDirectoryLocatorPresent(RandomAccessFile zip, long zipEndOfCentralDirectoryPosition)
Returns true if the provided file contains a ZIP64 End of Central Directory Locator.
long locatorPosition = zipEndOfCentralDirectoryPosition - ZIP64_EOCD_LOCATOR_SIZE;
if (locatorPosition < 0) {
    return false;
zip.seek(locatorPosition);
return zip.readInt() == ZIP64_EOCD_LOCATOR_SIG_REVERSE_BYTE_ORDER;