Here you can find the source of decompress(byte[] source)
Parameter | Description |
---|---|
source | byte array containing the compressed data |
Parameter | Description |
---|---|
IOException | if I/O error occurs |
public static byte[] decompress(byte[] source) throws IOException
//package com.java2s; /*//w w w .jav a 2 s . co m * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: Helper class containing common non-HTI-specific helper * functions that can be used in other java classes. * */ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.zip.InflaterInputStream; public class Main { /** * Decompresses the given byte array of compressed data. * Returns the decompressed data as a byte array. * * @param source byte array containing the compressed data * @return decompressed data as a byte array * @throws IOException if I/O error occurs */ public static byte[] decompress(byte[] source) throws IOException { // decompress the response through InflaterInputStream InflaterInputStream iis = new InflaterInputStream(new ByteArrayInputStream(source)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int readBytes; while ((readBytes = iis.read(buffer)) != -1) { baos.write(buffer, 0, readBytes); } iis.close(); return baos.toByteArray(); } }