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


Java GZIPInputStream.close方法代码示例

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


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

示例1: decompress

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public static String decompress(byte[] compressed) {
    if(compressed==null) return null;
    ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
    try {
        GZIPInputStream gis = new GZIPInputStream(bis);
        BufferedReader br = new BufferedReader(new InputStreamReader(gis, "UTF-8"));
        StringBuilder sb = new StringBuilder();
        String line;
        while((line = br.readLine()) != null) {
            sb.append(line);
        }
        br.close();
        gis.close();
        bis.close();
        return sb.toString();
    }catch (IOException ex){
        ex.printStackTrace();
    }
    return null;
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:21,代码来源:BundleUtils.java

示例2: unGZip

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
/**
 * GZip解压
 *
 * @param bContent
 * @return
 */
public static byte[] unGZip(byte[] bContent) {
    byte[] data = new byte[1024];
    try {
        ByteArrayInputStream in = new ByteArrayInputStream(bContent);
        GZIPInputStream pIn = new GZIPInputStream(in);
        DataInputStream objIn = new DataInputStream(pIn);
        int len = 0;
        int count = 0;
        while ((count = objIn.read(data, len, len + 1024)) != -1) {
            len = len + count;
        }
        byte[] trueData = new byte[len];
        System.arraycopy(data, 0, trueData, 0, len);
        objIn.close();
        pIn.close();
        in.close();

        return trueData;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:31,代码来源:IoUtils.java

示例3: decompressGzipFile

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public static void decompressGzipFile(String gzipFile, String newFile) {
    try {
        FileInputStream fis = new FileInputStream(gzipFile);
        GZIPInputStream gis = new GZIPInputStream(fis);
        FileOutputStream fos = new FileOutputStream(newFile);
        byte[] buffer = new byte[1024];
        int len;
        while((len = gis.read(buffer)) != -1){
            fos.write(buffer, 0, len);
        }
        //close resources
        fos.close();
        gis.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    
}
 
开发者ID:michael-hll,项目名称:BigQueryStudy,代码行数:19,代码来源:GZipHelper.java

示例4: unzipBigList

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
private static void unzipBigList() {
    try {
        FileInputStream inputStream = new FileInputStream(PATH+BIGLIST+ZIP);
        GZIPInputStream gzipInput = new GZIPInputStream(inputStream);
        FileOutputStream outputStream = new FileOutputStream(PATH+BIGLIST+TXT);
        int ch;
        while ((ch = gzipInput.read()) != -1) {
            outputStream.write(ch);
        }
        inputStream.close();
        gzipInput.close(); 
        outputStream.close();
    }
    catch (Exception err)
    {
         System.out.println("An error occurred - while unzipping "+PATH+BIGLIST+ZIP+" :\n" + err.getMessage());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:VCSClassLoadingTest.java

示例5: 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:nucypher,项目名称:hadoop-oss,代码行数:18,代码来源:WritableUtils.java

示例6: 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

示例7: readCompressedFile

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public String readCompressedFile(String fileName) {
    try {
        GZIPInputStream gis = new GZIPInputStream(new FileInputStream(fileName));
        ByteArrayOutputStream fos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len;
        while ((len = gis.read(buffer)) != -1) {
            fos.write(buffer, 0, len);
        }
        fos.close();
        gis.close();
        return new String(fos.toByteArray());
    } catch (IOException ex) {
        System.out.println("Invalid input file!");
        return null;
    }
}
 
开发者ID:mhdehghan,项目名称:SamanGar,代码行数:18,代码来源:ReadData.java

示例8: uncompress

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
private static byte[] uncompress(byte[] compressed) {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ByteArrayInputStream bais = new ByteArrayInputStream(compressed);
        GZIPInputStream gis = new GZIPInputStream(bais);
        byte[] buffer = new byte[0x1000];
        int length;
        while ((length = gis.read(buffer)) != -1) {
            if (length > 0) {
                baos.write(buffer, 0, length);
            }
        }
        gis.close();
        return baos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:19,代码来源:BreventProtocol.java

示例9: 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

示例10: b

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public static byte[] b(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,代码来源:l.java

示例11: decompress

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
private byte[] decompress(byte[] data) throws Throwable {
	ByteArrayInputStream bais = new ByteArrayInputStream(data);
	GZIPInputStream gzis = new GZIPInputStream(bais);
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	byte[] buf = new byte[1024];
	int len = gzis.read(buf);
	while (len > 0) {
		baos.write(buf, 0, len);
		len = gzis.read(buf);
	}
	baos.close();
	gzis.close();
	return baos.toByteArray();
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:15,代码来源:ProtocolBase.java

示例12: 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

示例13: copyDecompressed

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
public static void copyDecompressed(String resource, File output)
    throws IOException {
  URL input =  Resources.getResource(resource);
  FileOutputStream fos = new FileOutputStream(output);
  GZIPInputStream gzis = new GZIPInputStream(input.openStream());
  ByteStreams.copy(gzis, fos);
  fos.close();
  gzis.close();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:10,代码来源:TestUtils.java

示例14: decompress

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
/**
 * 数据解压缩
 * @param is
 * @param os
 * @throws Exception
 */
public static void decompress(InputStream is, OutputStream os) throws Exception {
	GZIPInputStream gis = new GZIPInputStream(is);
	int count;
	byte data[] = new byte[BUFFER];
	while ((count = gis.read(data, 0, BUFFER)) != -1) {
		os.write(data, 0, count);
	}
	gis.close();
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:16,代码来源:GZipUtils.java

示例15: run

import java.util.zip.GZIPInputStream; //导入方法依赖的package包/类
@Override
public void run() {
    super.run();

    String sourceFile = readStringArgument("sourceFile");
    String targetFile = readStringArgument("targetFile");

    try {
        GZIPInputStream gzInputStream
                = new GZIPInputStream(new FileInputStream(sourceFile));
        FileOutputStream outputStream
                = new FileOutputStream(targetFile);

        byte[] buffer = new byte[3072];
        int bytesRead;
        while ((bytesRead = gzInputStream.read(buffer)) > 0) {
            outputStream.write(buffer, 0, bytesRead);
        }

        gzInputStream.close();
        outputStream.close();
    } catch (Exception ex) {
        throw new RuntimeException(String.format(
                "Failed to extract data from file %s into file %s",
                sourceFile,
                targetFile), ex);
    }
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:29,代码来源:ExtractGzip.java


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