Here you can find the source of isZip(BufferedInputStream in)
Parameter | Description |
---|---|
in | the BufferedInputStream to test. |
public static boolean isZip(BufferedInputStream in)
//package com.java2s; import java.io.BufferedInputStream; import java.util.Arrays; public class Main { /**/*from w w w . jav a2s . c o m*/ * Test for ZIP stream signature. * * @param in the BufferedInputStream to test. * @return true if input stream is zip. */ public static boolean isZip(BufferedInputStream in) { in.mark(4); byte[] b = new byte[4]; byte[] zipSig = new byte[4]; zipSig[0] = 0x50; zipSig[1] = 0x4b; zipSig[2] = 0x03; zipSig[3] = 0x04; try { in.read(b, 0, 4); } catch (Exception ex) { throw new RuntimeException("Couldn't read header from stream ", ex); } try { in.reset(); } catch (Exception ex) { throw new RuntimeException("Couldn't reset stream ", ex); } return Arrays.equals(b, zipSig); } }