Java GZip File Check isGzipFile(File file)

Here you can find the source of isGzipFile(File file)

Description

Returns true if the input file is a gzip file.

License

Open Source License

Parameter

Parameter Description
file a parameter

Return

true if the file is a gzip file, false otherwise

Declaration

public static boolean isGzipFile(File file) 

Method Source Code


//package com.java2s;

import java.io.File;

public class Main {
    /**/* w w  w.  j  av  a 2 s  .c om*/
     * Suffix signifying a gzipped file
     */
    private static final String gz_suffix = ".gz";
    /**
     * Suffix signifying a gzipped tarball file
     */
    private static final String tgz_suffix = ".tgz";

    /**
     * Returns true if the input file is a gzip file. Determination is made by examining the file
     * suffix.
     * 
     * @param file
     * @return true if the file is a gzip file, false otherwise
     */
    public static boolean isGzipFile(File file) {
        return hasCaseInsensitiveSuffix(file, gz_suffix) || hasCaseInsensitiveSuffix(file, tgz_suffix);
    }

    /**
     * Matches the file suffix to the input file in a case-insensitive manner
     * 
     * @param file
     * @param fileSuffix
     * @return true if the input file has the specified file suffix regardless of upper/lower case
     */
    private static boolean hasCaseInsensitiveSuffix(File file, String fileSuffix) {
        return file.getName().endsWith(fileSuffix.toLowerCase())
                || file.getName().endsWith(fileSuffix.toUpperCase());
    }
}

Related

  1. isGzip(File file)
  2. isGzip(String file)
  3. isGZipEnding(File file)
  4. isGzipFile(File f)
  5. isGZipFile(File file)
  6. isGZIPFileEmpty(File f)
  7. isGzipFilename(File file)
  8. isGzipped(File f)