Here you can find the source of startsWithZipMagicBytes(byte[] data)
Returns whether the given bytes start with the <a href="http://en.wikipedia.org/wiki/Zip_%28file_format%29#File_headers" >magic bytes</a> that mark a ZIP file.
public static boolean startsWithZipMagicBytes(byte[] data)
//package com.java2s; /*-------------------------------------------------------------------------+ | | | Copyright 2005-2011 the ConQAT Project | | | | Licensed under the Apache License, Version 2.0 (the "License"); | | you may not use this file except in compliance with the License. | | You may obtain a copy of the License at | | | | http://www.apache.org/licenses/LICENSE-2.0 | | | | Unless required by applicable law or agreed to in writing, software | | distributed under the License is distributed on an "AS IS" BASIS, | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | See the License for the specific language governing permissions and | | limitations under the License. | +-------------------------------------------------------------------------*/ public class Main { /**// w ww . j a v a2 s .com * Returns whether the given bytes start with the <a * href="http://en.wikipedia.org/wiki/Zip_%28file_format%29#File_headers" * >magic bytes</a> that mark a ZIP file. */ public static boolean startsWithZipMagicBytes(byte[] data) { return isPrefix(new byte[] { 0x50, 0x4b, 0x03, 0x04 }, data); } /** Returns whether the prefix is a prefix of the given key. */ public static boolean isPrefix(byte[] prefix, byte[] key) { if (key.length < prefix.length) { return false; } for (int i = 0; i < prefix.length; ++i) { if (prefix[i] != key[i]) { return false; } } return true; } }