Java tutorial
//package com.java2s; /* * MultiServer - Multiple Server Communication Application * Copyright (C) 2015 Kyle Fricilone * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.*; import java.util.zip.GZIPInputStream; public class Main { /** * Uncompresses a GZIP file. * * @param bytes * The compressed bytes. * @return The uncompressed bytes. * @throws IOException * if an I/O error occurs. */ public static byte[] gunzip(byte[] bytes) throws IOException { /* create the streams */ InputStream is = new GZIPInputStream(new ByteArrayInputStream(bytes)); try { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { /* copy data between the streams */ byte[] buf = new byte[4096]; int len = 0; while ((len = is.read(buf, 0, buf.length)) != -1) { os.write(buf, 0, len); } } finally { os.close(); } /* return the uncompressed bytes */ return os.toByteArray(); } finally { is.close(); } } }