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


Java GZIPInputStream.read方法代码示例

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


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

示例1: readCompressedByteArray

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public static byte[] readCompressedByteArray(DataInput in) throws IOException {
  int length = in.readInt();
  if (length == -1) return null;
  byte[] buffer = new byte[length];
  in.readFully(buffer);      // could/should use readFully(buffer,0,length)?
  GZIPInputStream gzi = new GZIPInputStream(new ByteArrayInputStream(buffer, 0, buffer.length));
  byte[] outbuf = new byte[length];
  ByteArrayOutputStream bos =  new ByteArrayOutputStream();
  int len;
  while((len=gzi.read(outbuf, 0, outbuf.length)) != -1){
    bos.write(outbuf, 0, len);
  }
  byte[] decompressed =  bos.toByteArray();
  bos.close();
  gzi.close();
  return decompressed;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:WritableUtils.java

示例2: deserializeBundle

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public static Bundle deserializeBundle(final String base64) {
    Bundle bundle;

    final Parcel parcel = Parcel.obtain();
    try {
        final ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
        final byte[] buffer = new byte[1024];
        final GZIPInputStream zis = new GZIPInputStream(new ByteArrayInputStream(Base64.decode(base64, 0)));
        int len;
        while ((len = zis.read(buffer)) != -1) {
            byteBuffer.write(buffer, 0, len);
        }
        zis.close();
        parcel.unmarshall(byteBuffer.toByteArray(), 0, byteBuffer.size());
        parcel.setDataPosition(0);
        bundle = parcel.readBundle();
    } catch (IOException e) {
        e.printStackTrace();
        bundle = null;
    } finally {
        parcel.recycle();
    }

    return bundle;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:26,代码来源:BundleUtil.java

示例3: decode

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
/**
 * Decode a string back to a byte array.
 *
 * @param s the string to convert
 * @param uncompress use gzip to uncompress the stream of bytes
 *
 * @throws IOException if there's a gzip exception
 */
public static byte[] decode(final String s, final boolean uncompress) throws IOException {
    byte[] bytes;
    try (JavaReader jr = new JavaReader(new CharArrayReader(s.toCharArray()));
            ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        int ch;
        while ((ch = jr.read()) >= 0) {
            bos.write(ch);
        }
        bytes = bos.toByteArray();
    }
    if (uncompress) {
        final GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes));
        final byte[] tmp = new byte[bytes.length * 3]; // Rough estimate
        int count = 0;
        int b;
        while ((b = gis.read()) >= 0) {
            tmp[count++] = (byte) b;
        }
        bytes = new byte[count];
        System.arraycopy(tmp, 0, bytes, 0, count);
    }
    return bytes;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:Utility.java

示例4: uncompress

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
/**
 * 解压缩字符串
 *
 * @param str
 * @return String
 * @throws IOException
 */
public static String uncompress(String str) throws IOException {
    if (str == null || str.length() == 0) {
        return str;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayInputStream in = new ByteArrayInputStream(
            str.getBytes("ISO-8859-1"));
    GZIPInputStream gunzip = new GZIPInputStream(in);
    byte[] buffer = new byte[256];
    int n;
    while ((n = gunzip.read(buffer)) >= 0) {
        out.write(buffer, 0, n);
    }
    return out.toString("UTF-8");
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:23,代码来源:StringUtils.java

示例5: uncompress

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
@Override
public byte[] uncompress(byte[] data) throws IOException {
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	ByteArrayInputStream in = new ByteArrayInputStream(data);

	try {
		GZIPInputStream ungzip = new GZIPInputStream(in);
		byte[] buffer = new byte[2048];
		int n;
		while ((n = ungzip.read(buffer)) >= 0) {
			out.write(buffer, 0, n);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}

	return out.toByteArray();
}
 
开发者ID:yu120,项目名称:compress,代码行数:19,代码来源:GzipCompress.java

示例6: modifyBytes

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public byte[] modifyBytes(byte[] input) throws ModificationException{
    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(input);
        GZIPInputStream gzis = new GZIPInputStream(bais);

        byte[] buffer = new byte[input.length*2];
        int bytesRead;
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        while ((bytesRead = gzis.read(buffer)) != -1) {
            // I need to change this to accept arbitrary values
            if (bytesRead < input.length*2) {
                output.write(buffer, 0, bytesRead);
            } else {
                throw new ModificationException("Cannot Decompress, input too long.");
            }
        }
        return output.toByteArray();
    } catch (IOException e) {
        throw new ModificationException("Invalid GZIP Input");
    }
}
 
开发者ID:nccgroup,项目名称:Decoder-Improved,代码行数:22,代码来源:GZIPDecoder.java

示例7: testGzipDurability

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
@Test
public void testGzipDurability() throws Exception {
  Context context = new Context();
  HDFSCompressedDataStream writer = new HDFSCompressedDataStream();
  writer.configure(context);
  writer.open(fileURI, factory.getCodec(new Path(fileURI)),
      SequenceFile.CompressionType.BLOCK);

  String[] bodies = { "yarf!" };
  writeBodies(writer, bodies);

  byte[] buf = new byte[256];
  GZIPInputStream cmpIn = new GZIPInputStream(new FileInputStream(file));
  int len = cmpIn.read(buf);
  String result = new String(buf, 0, len, Charsets.UTF_8);
  result = result.trim(); // BodyTextEventSerializer adds a newline

  Assert.assertEquals("input and output must match", bodies[0], result);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:20,代码来源:TestHDFSCompressedDataStream.java

示例8: gzip_decompress

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public static byte[] gzip_decompress(byte[] bytes,int offset) {  
    if (bytes == null || bytes.length == 0) {  
        return null;  
    }  
    ByteArrayOutputStream out = new ByteArrayOutputStream();  
    ByteArrayInputStream in = new ByteArrayInputStream(bytes,offset, bytes.length-offset);  
    try {  
        GZIPInputStream ungzip = new GZIPInputStream(in);  
        byte[] buffer = new byte[256];  
        int n;  
        while ((n = ungzip.read(buffer)) >= 0) {  
            out.write(buffer, 0, n);  
        }  
    } catch (IOException e) {  
        e.printStackTrace();
    }  
  
    return out.toByteArray();  
}
 
开发者ID:KnIfER,项目名称:mdict-parser-java,代码行数:20,代码来源:mdictRes.java

示例9: unGZip

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
/***
 * 解压GZip
 *
 * @param data
 * @return
 */
public static byte[] unGZip(byte[] data) {
    byte[] b = null;
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(data);
        GZIPInputStream gzip = new GZIPInputStream(bis);
        byte[] buf = new byte[1024];
        int num = -1;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        while ((num = gzip.read(buf, 0, buf.length)) != -1) {
            baos.write(buf, 0, num);
        }
        b = baos.toByteArray();
        baos.flush();
        baos.close();
        gzip.close();
        bis.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return b;
}
 
开发者ID:mayabot,项目名称:mynlp,代码行数:28,代码来源:GzipUtils.java

示例10: uncompressToString

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public static String uncompressToString(byte[] b) {
	if (b == null || b.length == 0) {
		return null;
	}
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	ByteArrayInputStream in = new ByteArrayInputStream(b);
	try {
		GZIPInputStream gunzip = new GZIPInputStream(in);
		byte[] buffer = new byte[256];
		int n;
		while ((n = gunzip.read(buffer)) >= 0) {
			out.write(buffer, 0, n);
		}
	} catch (IOException e) {
		log.error(e.getMessage(),e);
	}
	return out.toString();
}
 
开发者ID:xiaomin0322,项目名称:marathon-auth-plugin,代码行数:19,代码来源:MessageGZIP.java

示例11: a

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public static byte[] a(byte[] bArr) {
    InputStream byteArrayInputStream = new ByteArrayInputStream(bArr);
    GZIPInputStream gZIPInputStream = new GZIPInputStream(byteArrayInputStream);
    byte[] bArr2 = new byte[4096];
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(bArr.length * 2);
    while (true) {
        int read = gZIPInputStream.read(bArr2);
        if (read != -1) {
            byteArrayOutputStream.write(bArr2, 0, read);
        } else {
            bArr2 = byteArrayOutputStream.toByteArray();
            byteArrayInputStream.close();
            gZIPInputStream.close();
            byteArrayOutputStream.close();
            return bArr2;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:19,代码来源:k.java

示例12: decode

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> out) throws Exception {
    if(in.readableBytes() < 8) return;
    in.markReaderIndex();
    int typeId = in.readInt();
    int len = in.readInt();
    if (in.readableBytes() < len) {
        // System.out.println("[NETTY] Expecting ID " + typeId + " with length " + len);
        in.resetReaderIndex();
        return;
    }
    // System.out.println("[NETTY] Message ID=" + typeId + " received with readableBytes=" + in.readableBytes());

    Message prototype = register.getDesiredMessagePrototype(typeId);
    if(prototype == null) {
        throw new IllegalArgumentException("Unrecognisable message type ID! ");
    }

    // System.out.println("Received message [" + prototype.getClass().getSimpleName() + "]");

    byte[] messageData = new byte[len];
    in.readBytes(messageData);

    if(messageData.length <= 0){
        out.add(prototype.getParserForType().parseFrom(messageData, 0, len));
        return;
    }

    byte[] decompressBuffer = new byte[2048];

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GZIPInputStream inp = new GZIPInputStream(new ByteArrayInputStream(messageData));
    int lBuff;
    while((lBuff = inp.read(decompressBuffer)) != -1) {
        bos.write(decompressBuffer, 0, lBuff);
    }
    inp.close();
    byte[] decompressedData = bos.toByteArray();
    out.add(prototype.getParserForType().parseFrom(decompressedData, 0, decompressedData.length));
}
 
开发者ID:CloudLandGame,项目名称:CloudLand-Server,代码行数:41,代码来源:IdBasedProtobufDecoder.java

示例13: decompress

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
/**
 * @param data
 *            Data to decompress
 * @return Decompressed data
 * @throws IOException
 */
public static byte[] decompress(byte[] data) throws IOException {
	ByteArrayOutputStream bout = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
	ByteArrayInputStream bin = new ByteArrayInputStream(data);
	GZIPInputStream gin = new GZIPInputStream(bin);
	byte[] tmp = new byte[DEFAULT_BUFFER_SIZE];
	int length = gin.read(tmp);
	while (length > -1) {
		bout.write(tmp, 0, length);
		length = gin.read(tmp);
	}
	return bout.toByteArray();
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:19,代码来源:GzipInterceptor.java

示例14: decompress

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
/**
 * @param data  Data to decompress
 * @return      Decompressed data
 * @throws IOException
 */
public static byte[] decompress(byte[] data) throws IOException {
    ByteArrayOutputStream bout =
        new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
    ByteArrayInputStream bin = new ByteArrayInputStream(data);
    GZIPInputStream gin = new GZIPInputStream(bin);
    byte[] tmp = new byte[DEFAULT_BUFFER_SIZE];
    int length = gin.read(tmp);
    while (length > -1) {
        bout.write(tmp, 0, length);
        length = gin.read(tmp);
    }
    return bout.toByteArray();
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:19,代码来源:GzipInterceptor.java

示例15: getMapFromZippedFile

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public static Object getMapFromZippedFile(String path) {
    File file = new File(path);
    Object result = null;
    try {
        if (file.exists()) {
            FileInputStream fileIn = new FileInputStream(file);
            GZIPInputStream gzipIn = new GZIPInputStream(fileIn);
            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
            int count;
            byte[] data = new byte[1024];
            while ((count = gzipIn.read(data, 0, 1024)) != -1) {
                byteOut.write(data, 0, count);
            }
            ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
            ObjectInputStream oi = new ObjectInputStream(byteIn);
            result = oi.readObject();
            fileIn.close();
            gzipIn.close();
            oi.close();
        } else {
            throw new RuntimeException("getMapFromZippedFile error,file doesn't exist ,path is " + path);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("getMapFromZippedFile from " + path + "  error ");
    }
    return result;
}
 
开发者ID:Meituan-Dianping,项目名称:Robust,代码行数:29,代码来源:JavaUtils.java


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