List of usage examples for java.util.zip GZIPInputStream GZIP_MAGIC
int GZIP_MAGIC
To view the source code for java.util.zip GZIPInputStream GZIP_MAGIC.
Click Source Link
From source file:Main.java
static public final boolean isGzipStm(InputStream in) throws IOException { boolean ms = in.markSupported(); if (ms)/*from ww w.j a v a2 s. com*/ in.mark(10); int b1 = in.read(); int b2 = in.read(); if (ms) in.reset(); return ((b2 << 8 | b1) == GZIPInputStream.GZIP_MAGIC); }
From source file:Main.java
/** * Checks the InputStream if it contains GZIP compressed data * * @param inputStream InputStream to be checked * @return true or false if the stream contains GZIP compressed data * @throws java.io.IOException/* w w w. java 2s .co m*/ */ public static boolean isInputStreamGZIPCompressed(final PushbackInputStream inputStream) throws IOException { if (inputStream == null) return false; byte[] signature = new byte[2]; int readStatus = inputStream.read(signature); inputStream.unread(signature); int streamHeader = ((int) signature[0] & 0xff) | ((signature[1] << 8) & 0xff00); return readStatus == 2 && GZIPInputStream.GZIP_MAGIC == streamHeader; }
From source file:org.mule.util.compression.GZipCompression.java
/** * Determines if a byte array is compressed. The java.util.zip GZip * implementaiton does not expose the GZip header so it is difficult to determine * if a string is compressed.//from www .j a v a2s . c om * * @param bytes an array of bytes * @return true if the array is compressed or false otherwise * @throws java.io.IOException if the byte array couldn't be read */ public boolean isCompressed(byte[] bytes) throws IOException { if ((bytes == null) || (bytes.length < 2)) { return false; } else { return ((bytes[0] == (byte) (GZIPInputStream.GZIP_MAGIC)) && (bytes[1] == (byte) (GZIPInputStream.GZIP_MAGIC >> 8))); } }
From source file:io.dacopancm.socketdcm.helper.HelperUtil.java
public static boolean isCompressed(byte[] bytes) throws IOException { if ((bytes == null) || (bytes.length < 2)) { return false; } else {// w w w . jav a 2s .co m return ((bytes[0] == (byte) (GZIPInputStream.GZIP_MAGIC)) && (bytes[1] == (byte) (GZIPInputStream.GZIP_MAGIC >> 8))); } }
From source file:com.blockwithme.longdb.tools.Utils.java
/** Reads first 2 bytes, checks if its equal to GZIPInputStream.GZIP_MAGIC * //from w ww . j a v a2s . c om * @param theFile * the file * @return true, if compressed * @throws Exception */ public static boolean compressed(final File theFile) throws Exception { // TODO: I the file name ends with .gz, then I think that we // don't need to check FileInputStream fis = null; try { fis = FileUtils.openInputStream(theFile); while (true) { final byte[] bytes = new byte[2]; fis.read(bytes); final int head = (bytes[0] & BYTE_MASK) | ((bytes[1] << BYTE_BITS) & SECOND_BYTE_MASK); return head == GZIPInputStream.GZIP_MAGIC; } } finally { if (fis != null) fis.close(); } }
From source file:gedi.util.io.text.LineOrientedFile.java
public boolean isGZIP() throws IOException { if (gzipped == null) { if (!exists()) gzipped = getPath().endsWith(".gz"); else {//from w w w. j a v a 2 s . c o m InputStream in = createInputStream(); try { gzipped = in.read() == (GZIPInputStream.GZIP_MAGIC & 0xFF) && in.read() == (GZIPInputStream.GZIP_MAGIC >> 8); } finally { in.close(); } } } return gzipped; }
From source file:byps.BWire.java
/** * Reads a ByteBuffer from an InputStream * Closes the InputStream./*from w ww.j a v a 2s . c om*/ * @param is * @return * @throws IOException */ public static ByteBuffer bufferFromStream(InputStream is, Boolean gzip) throws IOException { if (is == null) return null; try { ByteBuffer ibuf = ByteBuffer.allocate(10 * 1000); if (gzip != null) { if (gzip) { is = new GZIPInputStream(is); } } else { if (!is.markSupported()) is = new BufferedInputStream(is, 2); is.mark(2); int magic = is.read() | (is.read() << 8); is.reset(); if (magic == GZIPInputStream.GZIP_MAGIC) { is = new GZIPInputStream(is); } } ReadableByteChannel rch = Channels.newChannel(is); while (rch.read(ibuf) != -1) { if (ibuf.remaining() == 0) { ByteBuffer nbuf = ByteBuffer.allocate(ibuf.capacity() * 2); ibuf.flip(); nbuf.put(ibuf); ibuf = nbuf; } } ibuf.flip(); return ibuf; } finally { is.close(); } }
From source file:com.netflix.dyno.connectionpool.impl.utils.ZipUtils.java
/** * Determines if a byte array is compressed. The java.util.zip GZip * implementation does not expose the GZip header so it is difficult to determine * if a string is compressed.//from www .j av a2s . co m * * @param bytes an array of bytes * @return true if the array is compressed or false otherwise * @throws java.io.IOException if the byte array couldn't be read */ public static boolean isCompressed(byte[] bytes) throws IOException { return bytes != null && bytes.length >= 2 && bytes[0] == (byte) (GZIPInputStream.GZIP_MAGIC) && bytes[1] == (byte) (GZIPInputStream.GZIP_MAGIC >> 8); }
From source file:com.breadwallet.tools.util.BRCompressor.java
public static boolean isGZIPStream(byte[] bytes) { return bytes[0] == (byte) GZIPInputStream.GZIP_MAGIC && bytes[1] == (byte) (GZIPInputStream.GZIP_MAGIC >>> 8); }
From source file:org.bndtools.rt.repository.server.RepositoryResourceComponent.java
private static boolean isGZip(InputStream bufferedStream) throws IOException { assert bufferedStream.markSupported(); bufferedStream.mark(2);/*from ww w .ja va2 s.c o m*/ int magic = readUShort(bufferedStream); bufferedStream.reset(); return magic == GZIPInputStream.GZIP_MAGIC; }