Java GZip File Check isGZipped(final File f)

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

Description

is G Zipped

License

Apache License

Declaration

public static boolean isGZipped(final File f) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    public static boolean isGZipped(final File f) throws IOException {
        return isGZipped(new FileInputStream(f));
    }/*  w  w  w.ja  v  a 2s . co m*/

    public static boolean isGZipped(final InputStream s) throws IOException {
        try {
            final byte[] toRead = new byte[2];
            final int readBytes = s.read(toRead);
            if (readBytes < 2) {
                return false;
            }
            final byte b1 = (byte) 0x1f;
            final byte b2 = (byte) 0x8b;
            return (toRead[0] == b1 && toRead[1] == b2);
        } finally {
            s.close();
        }
    }
}

Related

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