集册 Java实例教程 gunzip对象

gunzip对象

欢马劈雪     最近更新时间:2020-01-02 10:19:05

541
gunzip对象


//package com.nowjava;

import java.io.ByteArrayInputStream;
// 来自 NowJava.com - 时代Java

import java.io.Closeable;

import java.io.IOException;


import java.io.ObjectInputStream;


import java.io.Serializable;

import java.util.zip.GZIPInputStream;


public class Main {

    public static Serializable gunzipObject(byte[] bytes)/*时 代      J a v a   公   众 号 - nowjava.com 提供*/

            throws IOException, ClassNotFoundException {


        ByteArrayInputStream baIn = null;

        GZIPInputStream gzIn = null;

        ObjectInputStream objIn = null;

        try {

            baIn = new ByteArrayInputStream(bytes);

            gzIn = new GZIPInputStream(baIn);

            objIn = new ObjectInputStream(gzIn);

            return (Serializable) objIn.readObject();

        } finally {

            closeQuietly(objIn);

            closeQuietly(gzIn);

            closeQuietly(baIn);

        }


    }


    public static void closeQuietly(
展开阅读全文