Java GZip File Check isGzipped(File f)

Here you can find the source of isGzipped(File f)

Description

is Gzipped

License

Open Source License

Declaration

public static boolean isGzipped(File f) 

Method Source Code

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

import java.io.Closeable;

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static boolean isGzipped(File f) {
        InputStream is = null;//from  w w w .  j a  v  a2  s.  c o m
        try {
            is = new FileInputStream(f);
            byte[] signature = new byte[2];
            int nread = is.read(signature); //read the gzip signature
            return nread == 2 && signature[0] == (byte) 0x1f && signature[1] == (byte) 0x8b;
        } catch (IOException e) {
            return false;
        } finally {
            closeSafely(is);
        }
    }

    private static void closeSafely(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Related

  1. isGzipFile(File f)
  2. isGZipFile(File file)
  3. isGzipFile(File file)
  4. isGZIPFileEmpty(File f)
  5. isGzipFilename(File file)
  6. isGzipped(File file)
  7. isGZipped(final File f)
  8. isGzipped(final File file)
  9. isGZipped(final File file)