Java Utililty Methods GZip File Check

List of utility methods to do GZip File Check

Description

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

Method

booleanisGzip(File file)
Gets if the file is compressed with gzip.
try {
    RandomAccessFile raf = new RandomAccessFile(file, "r");
    int magic = raf.read() & 0xff | (raf.read() << 8) & 0xff00;
    raf.close();
    return magic == GZIPInputStream.GZIP_MAGIC;
} catch (Exception e) {
    e.printStackTrace();
return false;
booleanisGzip(String file)
is Gzip
return isGzip(new File(file));
booleanisGZipEnding(File file)
is G Zip Ending
return endsWith(file, ".gz");
booleanisGzipFile(File f)
is Gzip File
FileInputStream fis = null;
try {
    fis = new FileInputStream(f);
    GZIPInputStream gs = new GZIPInputStream(fis);
} catch (FileNotFoundException e) {
    return false;
} catch (IOException e) {
    return false;
...
booleanisGZipFile(File file)
is G Zip File
boolean rv = false;
if (file != null) {
    String fileName = file.getName();
    if (fileName != null) {
        if (fileName.toLowerCase().endsWith(".gz")) {
            rv = true;
return rv;
booleanisGzipFile(File file)
Returns true if the input file is a gzip file.
return hasCaseInsensitiveSuffix(file, gz_suffix) || hasCaseInsensitiveSuffix(file, tgz_suffix);
booleanisGZIPFileEmpty(File f)
is GZIP File Empty
InputStream in = new GZIPInputStream(new FileInputStream(f));
try {
    return in.read() == -1;
} finally {
    in.close();
booleanisGzipFilename(File file)
is Gzip Filename
return isGzipFilename(file.getName());
booleanisGzipped(File f)
is Gzipped
InputStream is = null;
try {
    is = new FileInputStream(f);
    byte[] signature = new byte[2];
    int nread = is.read(signature); 
    return nread == 2 && signature[0] == (byte) 0x1f && signature[1] == (byte) 0x8b;
} catch (IOException e) {
    return false;
...
booleanisGzipped(File file)
Returns true if file has a .gz extension
return file.getName().endsWith(".gz");