当前位置: 首页>>代码示例>>Java>>正文


Java GZIPInputStream.GZIP_MAGIC属性代码示例

本文整理汇总了Java中java.util.zip.GZIPInputStream.GZIP_MAGIC属性的典型用法代码示例。如果您正苦于以下问题:Java GZIPInputStream.GZIP_MAGIC属性的具体用法?Java GZIPInputStream.GZIP_MAGIC怎么用?Java GZIPInputStream.GZIP_MAGIC使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.util.zip.GZIPInputStream的用法示例。


在下文中一共展示了GZIPInputStream.GZIP_MAGIC属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isInputStreamGZIPCompressed

/**
 * 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 if read from inputStream fails
 */
public static boolean isInputStreamGZIPCompressed(final PushbackInputStream inputStream) throws IOException {
    if (inputStream == null)
        return false;

    byte[] signature = new byte[2];
    int count = 0;
    try {
        while (count < 2) {
            int readCount = inputStream.read(signature, count, 2 - count);
            if (readCount < 0) return false;
            count = count + readCount;
        }
    } finally {
        inputStream.unread(signature, 0, count);
    }
    int streamHeader = ((int) signature[0] & 0xff) | ((signature[1] << 8) & 0xff00);
    return GZIPInputStream.GZIP_MAGIC == streamHeader;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:AsyncHttpClient.java

示例2: isGZipped

public static boolean isGZipped(byte[] bytes) {
	if ((bytes == null) || (bytes.length < 2)) {
		return false;
	} else {
		return ((bytes[0] == (byte) (GZIPInputStream.GZIP_MAGIC))
				&& (bytes[1] == (byte) (GZIPInputStream.GZIP_MAGIC >> 8)));
	}
}
 
开发者ID:nshusa,项目名称:rsam-gui,代码行数:8,代码来源:GZipUtils.java

示例3: maybeDecompress

private static InputStream maybeDecompress(InputStream input) throws IOException {
    // Due to a bug, Jira sometimes returns double-compressed responses. See JRA-37608
    BufferedInputStream buffered = new BufferedInputStream(input, 2);
    buffered.mark(2);
    int[] buf = new int[2];
    buf[0] = buffered.read();
    buf[1] = buffered.read();
    buffered.reset();
    int header = (buf[1] << 8) | buf[0];
    if (header == GZIPInputStream.GZIP_MAGIC) {
        return new GZIPInputStream(buffered);
    } else {
        return buffered;
    }
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:15,代码来源:HttpClient.java

示例4: isCompressed

/**
 * 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.
 *
 * @return true if the array is compressed or false otherwise
 */
public boolean isCompressed() {
    if ((bytes == null) || (bytes.length < 2)) {
        return false;
    } else {
        return ((bytes[0] == (byte) (GZIPInputStream.GZIP_MAGIC))
                && (bytes[1] == (byte) (GZIPInputStream.GZIP_MAGIC >> 8)));
    }
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:15,代码来源:Download.java

示例5: unGzipBytesToString

public static String unGzipBytesToString(InputStream in) {

        try {
            PushbackInputStream pis = new PushbackInputStream(in, 2);
            byte[] signature = new byte[2];
            pis.read(signature);
            pis.unread(signature);
            int head = ((signature[0] & 0x00FF) | ((signature[1] << 8) & 0xFF00));
            if (head != GZIPInputStream.GZIP_MAGIC) {
                return new String(toByteArray(pis), "UTF-8").trim();
            }
            GZIPInputStream gzip = new GZIPInputStream(pis);
            byte[] readBuf = new byte[8 * 1024];
            ByteArrayOutputStream outputByte = new ByteArrayOutputStream();
            int readCount = 0;
            do {
                readCount = gzip.read(readBuf);
                if (readCount > 0) {
                    outputByte.write(readBuf, 0, readCount);
                }
            } while (readCount > 0);
            closeQuietly(gzip);
            closeQuietly(pis);
            closeQuietly(in);
            if (outputByte.size() > 0) {
                return new String(outputByte.toByteArray());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
 
开发者ID:vsona,项目名称:RxJava2RetrofitDemo,代码行数:32,代码来源:StringUtils.java

示例6: isInputStreamGZIPCompressed

/**
 * 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
 */
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;
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:17,代码来源:AsyncHttpClient.java

示例7: isInputStreamGZIPCompressed

/**
 * 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 IOException
 */
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;
}
 
开发者ID:yiwent,项目名称:Mobike,代码行数:17,代码来源:AsyncHttpClient.java

示例8: decompressStream

private InputStream decompressStream(InputStream input) throws IOException {
    PushbackInputStream pb = new PushbackInputStream(input, 2);
    byte[] bytes = new byte[2];
    pb.read(bytes);
    pb.unread(bytes);
    int head = ((int) bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
    if (GZIPInputStream.GZIP_MAGIC == head)
        return new GZIPInputStream(pb);
    else
        return pb;
}
 
开发者ID:tiberiusteng,项目名称:financisto1-holo,代码行数:11,代码来源:DatabaseImport.java

示例9: isCompressed

public static boolean isCompressed (final byte[] compressed) {
    return (compressed[0] == (byte) (GZIPInputStream.GZIP_MAGIC)) && (compressed[1] == (byte) (GZIPInputStream.GZIP_MAGIC >> 8));
}
 
开发者ID:LeeKyoungIl,项目名称:illuminati,代码行数:3,代码来源:StringObjectUtils.java

示例10: isCompressedByGZIP

/**
 * Check if a byte array is compressed by GZIP
 * 
 * @param byteArr
 *            a byte array
 * @return true stands for compressed data; false stands for uncompressed data
 * @throws IOException
 */
public static boolean isCompressedByGZIP(byte[] byteArr) throws IOException {

    ByteArrayInputStream bis = new ByteArrayInputStream(byteArr);
    int b = readUByte(bis);
    int num = readUByte(bis) << 8 | b;
    return num == GZIPInputStream.GZIP_MAGIC;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:15,代码来源:CompressHelper.java

示例11: isCompressed

/**
 * Checks if is compressed.
 *
 * @param compressed the compressed
 * @return true, if is compressed
 */
public static boolean isCompressed(final byte[] compressed) {
	return (compressed[0] == (byte) (GZIPInputStream.GZIP_MAGIC))
			&& (compressed[1] == (byte) (GZIPInputStream.GZIP_MAGIC >> 8));
}
 
开发者ID:NEMPH,项目名称:nem-apps-lib,代码行数:10,代码来源:GzipUtils.java

示例12: isGzipStream

/**
 * Tests for a gzip byte array.
 *
 * <p>Source: https://www.javacodegeeks.com/2015/01/working-with-gzip-and-compressed-data.html
 *
 * @param bytes the bytes to test
 * @return true if a gzip byte array
 */
public static boolean isGzipStream(byte[] bytes) {
  return bytes[0] == (byte) GZIPInputStream.GZIP_MAGIC
      && bytes[1] == (byte) (GZIPInputStream.GZIP_MAGIC >>> 8);
}
 
开发者ID:OrdnanceSurvey,项目名称:vt-support,代码行数:12,代码来源:CompressUtil.java


注:本文中的java.util.zip.GZIPInputStream.GZIP_MAGIC属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。