Java GZip File Check isGZipped(final File file)

Here you can find the source of isGZipped(final File file)

Description

is G Zipped

License

Open Source License

Declaration

public static boolean isGZipped(final File file) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.RandomAccessFile;
import java.util.zip.GZIPInputStream;

public class Main {
    public static boolean isGZipped(final File file) {
        // code taken from: http://stackoverflow.com/a/30507742/3094906
        int magic = 0;
        try {//from  w ww  .  ja  v  a  2s  .  co  m
            RandomAccessFile raf = new RandomAccessFile(file, "r");
            magic = raf.read() & 0xff | raf.read() << 8 & 0xff00;
            raf.close();
        } catch (Throwable e) {
            e.printStackTrace(System.err);
        }
        return magic == GZIPInputStream.GZIP_MAGIC;
    }
}

Related

  1. isGzipFilename(File file)
  2. isGzipped(File f)
  3. isGzipped(File file)
  4. isGZipped(final File f)
  5. isGzipped(final File file)
  6. isGzipped(String fileName)
  7. isGZipped(String name)