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(File file)
Returns true if the input file is a zip file.
return hasCaseInsensitiveSuffix(file, zip_suffix);
booleanisZipFile(File file)
is Zip File
return file != null && isZipFile(file.getAbsolutePath());
booleanisZipFile(File file)
is Zip File
boolean isZip = true;
byte[] buffer = new byte[ZIP_HEADER.length];
RandomAccessFile raf = null;
try {
    raf = new RandomAccessFile(file, "r");
    raf.readFully(buffer);
    for (int i = 0; i < ZIP_HEADER.length; i++) {
        if (buffer[i] != ZIP_HEADER[i]) {
...
booleanisZipFile(File file)
is Zip File
if (file == null || file.isDirectory() || !file.canRead() || file.length() < 4) {
    return false;
try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)))) {
    int test = in.readInt();
    return test == 0x504b0304; 
} catch (Exception e) {
    return false;
...
booleanisZipFile(File file)
Check whether the given file is a ZIP-file.
String fileName = file.getPath().toLowerCase();
return (fileName.endsWith(".zip"));
booleanisZipFile(File file)
A quick test to determine if uploaded file is a ZIP file

boolean isZipFile = false;
FileInputStream fileInputStream = null;
try {
    fileInputStream = new FileInputStream(file);
    if (fileInputStream.available() > ZIP_SIGNATURE.length) {
        byte[] magic = new byte[ZIP_SIGNATURE.length];
        if (ZIP_SIGNATURE.length == fileInputStream.read(magic, 0, ZIP_SIGNATURE.length)) {
            isZipFile = Arrays.equals(magic, ZIP_SIGNATURE);
...
booleanisZipFile(File file)
is Zip File
boolean b = false;
try {
    ZipFile zf = new ZipFile(file);
    zf.close();
    b = true;
} catch (ZipException e) {
    e.printStackTrace();
} catch (IOException e) {
...
booleanisZipFile(File file)
is Zip File
if (file != null && file.getName() != null && file.getName().toLowerCase().endsWith(ZIP_FILE.toLowerCase()))
    return true;
else
    return false;
booleanisZipFile(File file)
Returns true if the given file is a zip file and false otherwise.
return file.isFile() && file.getName().toLowerCase().endsWith(ZIP_EXTENSION);
booleanisZipFile(InputStream stream)
is Zip File
DataInputStream in = new DataInputStream(stream);
if (stream.markSupported())
    stream.mark(INT_LENGTH);
int test = in.readInt();
if (stream.markSupported())
    stream.reset();
final int zipVerificationCode = ZIP_VERIFICATION_CODE;
return test == zipVerificationCode;
...