Here you can find the source of isZipped(InputStream inputStream)
Parameter | Description |
---|---|
IOException | an exception |
true
if the resource URI represents a zipped file.
public static boolean isZipped(InputStream inputStream) throws IOException
//package com.java2s; /* license-start//from w ww. j a va 2 s .c o m * * Copyright (C) 2008 - 2013 Crispico, <http://www.crispico.com/>. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details, at <http://www.gnu.org/licenses/>. * * Contributors: * Crispico - Initial API and implementation * * license-end */ import java.io.DataInputStream; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; public class Main { /** * Checks the first four bytes of a given resource and determines if it is * zipped or not. * * @return <code>true</code> if the resource URI {@link #getURI()} * represents a zipped file. * @throws IOException */ public static boolean isZipped(InputStream inputStream) throws IOException { DataInputStream dis = new DataInputStream(inputStream); try { return dis.readInt() == 0x504b0304; } catch (EOFException e) { // has less then 4 bytes // it can't be zipped return false; } finally { dis.close(); } } }