Java Zip File Check isZipFile(InputStream stream)

Here you can find the source of isZipFile(InputStream stream)

Description

is Zip File

License

GNU General Public License

Parameter

Parameter Description
stream aa

Exception

Parameter Description
IOException aa

Return

aa

Declaration

public static boolean isZipFile(InputStream stream) throws IOException 

Method Source Code

//package com.java2s;
/* DigiDoc4J library/*from  w w  w.  j  av a  2s .c  o  m*/
 *
 * This software is released under either the GNU Library General Public
 * License (see LICENSE.LGPL).
 *
 * Note that the only valid version of the LGPL license as far as this
 * project is concerned is the original GNU Library General Public License
 * Version 2.1, February 1999
 */

import java.io.*;

public class Main {
    private static final int ZIP_VERIFICATION_CODE = 0x504b0304;
    private static final int INT_LENGTH = 4;

    /**
     * @param stream aa
     * @return aa
     * @throws IOException aa
     */
    public static boolean isZipFile(InputStream stream) throws IOException {
        DataInputStream in = new DataInputStream(stream);

        if (stream.markSupported())
            stream.mark(INT_LENGTH);

        int test = in.readInt();

        if (stream.markSupported())
            stream.reset();

        final int zipVerificationCode = ZIP_VERIFICATION_CODE;
        return test == zipVerificationCode;
    }

    /**
     * @param file aa
     * @return aa
     * @throws IOException aa
     */
    public static boolean isZipFile(File file) throws IOException {
        try (FileInputStream stream = new FileInputStream(file)) {
            return isZipFile(stream);
        }
    }
}

Related

  1. isZipFile(File file)
  2. isZipFile(File file)
  3. isZipFile(File file)
  4. isZipFile(File file)
  5. isZipFile(File file)
  6. isZipFile(java.io.File file)
  7. isZipFile(String fileName)
  8. isZipFile(String fileName)
  9. isZipFile(String path)