Here you can find the source of isZipFile(InputStream stream)
Parameter | Description |
---|---|
stream | aa |
Parameter | Description |
---|---|
IOException | aa |
public static boolean isZipFile(InputStream stream) throws IOException
//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); } } }