Here you can find the source of isZipStream(InputStream in)
Parameter | Description |
---|---|
in | the input stream to test. |
public static boolean isZipStream(InputStream in) throws Throwable
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] MAGIC = { 'P', 'K', 0x3, 0x4 }; /**/*w w w . j a v a2s. c o m*/ * The method to test if a input stream is a zip archive. * * @param in * the input stream to test. * @return */ public static boolean isZipStream(InputStream in) throws Throwable { if (!in.markSupported()) { throw new IOException("The stream does not support mark."); } boolean isZip = true; try { in.mark(MAGIC.length); for (int i = 0; i < MAGIC.length; i++) { if (MAGIC[i] != (byte) in.read()) { isZip = false; break; } } in.reset(); } catch (IOException e) { isZip = false; } return isZip; } }