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

booleanisZipFile(java.io.File file)
Checks is specified file is zip file or not.
if (file.isDirectory()) {
    return false;
byte[] bytes = new byte[4];
try (FileInputStream fIn = new FileInputStream(file)) {
    if (fIn.read(bytes) != 4) {
        return false;
final int header = bytes[0] + (bytes[1] << 8) + (bytes[2] << 16) + (bytes[3] << 24);
return 0x04034b50 == header;
booleanisZipFile(String fileName)
Determine whether the file with the given filename is in .zip or .jar format.
if (fileName == null || fileName.trim().length() == 0) {
    return false;
ZipFile zipFile = null;
try {
    zipFile = new ZipFile(fileName.trim());
} catch (IOException ioException) {
    return false;
...
booleanisZipFile(String fileName)
is Zip File
if (fileName == null) {
    return false;
File file = new File(fileName);
if (!file.exists() || !file.isFile()) {
    return false;
InputStream in = null;
...
booleanisZipFile(String path)
is Zip File
if (path == null)
    return false;
try {
    new ZipFile(path).close();
    ;
    return true;
} catch (IOException e) {
    return false;
...
booleanisZipOrJarArchive(File file)
Test if a file is a ZIP or JAR archive.
boolean isArchive = true;
ZipFile zipFile = null;
try {
    zipFile = new ZipFile(file);
} catch (ZipException zipCurrupted) {
    isArchive = false;
} catch (IOException anyIOError) {
    isArchive = false;
...
booleanisZipped(File f)
Checks if a file is zipped.
try {
    RandomAccessFile raf = new RandomAccessFile(f, "r");
    long n = raf.readInt();
    raf.close();
    if (n == 0x504B0304) {
        return true;
    } else {
        return false;
...
booleanisZipped(File file)
is Zipped
try {
    return new ZipInputStream(new FileInputStream(file)).getNextEntry() != null;
} catch (IOException e) {
    return false;
booleanisZipped(final File file)
is Zipped
final String name = file.getName().toLowerCase();
for (String ext : extList) {
    if (name.endsWith(ext))
        return true;
return false;
booleanisZipped(InputStream inputStream)
Checks the first four bytes of a given resource and determines if it is zipped or not.
DataInputStream dis = new DataInputStream(inputStream);
try {
    return dis.readInt() == 0x504b0304;
} catch (EOFException e) {
    return false;
} finally {
    dis.close();
booleanisZipped(String name)
Returns true if file is in Zip format and false if it is not.
long n = 0x0;
File file = null;
RandomAccessFile raf = null;
try {
    try {
        file = new File(name);
        if (!file.exists()) {
            return false;
...