Java Byte Array Uncompress uncompress(final byte[] compressedData)

Here you can find the source of uncompress(final byte[] compressedData)

Description

Método que descomprime una entrada.

License

Open Source License

Parameter

Parameter Description
compressedData Entrada a descomprimir.

Return

Entrada descomprimida.

Declaration

static byte[] uncompress(final byte[] compressedData) 

Method Source Code


//package com.java2s;
/* Copyright (C) 2011 [Gobierno de Espana]
 * This file is part of "Cliente @Firma".
 * "Cliente @Firma" 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 2 of the License, or (at your option) any later version.
 *   - or The European Software License; either version 1.1 or (at your option) any later version.
 * Date: 11/01/11//from  w ww .j a v  a2s  . c o m
 * You may contact the copyright holder at: soporte.afirma5@mpt.es
 */

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.logging.Logger;

import java.util.zip.Inflater;

public class Main {
    private static final int COMPRESS_BUFFER_SIZE = 1024;

    /** Método que descomprime una entrada.
     * @param compressedData Entrada a descomprimir.
     * @return Entrada descomprimida. */
    static byte[] uncompress(final byte[] compressedData) {

        // Creamos el descompresor y le pasamos los datos
        final Inflater decompressor = new Inflater();
        decompressor.setInput(compressedData);

        final ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);

        // Descomprimimos
        final byte[] buf = new byte[COMPRESS_BUFFER_SIZE];
        while (!decompressor.finished()) {
            try {
                final int count = decompressor.inflate(buf);
                bos.write(buf, 0, count);
            } catch (final Exception e) {
                Logger.getLogger("es.gob.afirma").severe("Error descomprimiendo los datos: " + e); //$NON-NLS-1$ //$NON-NLS-2$
                break;
            }
        }
        try {
            bos.close();
        } catch (final IOException e) {
            // Ignoramos los errores en el cierre
        }

        return bos.toByteArray();

    }
}

Related

  1. uncompress(byte[] b)
  2. uncompress(byte[] data)
  3. uncompress(byte[] gzData, String charset)
  4. uncompress(byte[] input, int uncompr_len)
  5. uncompress(final byte[] buffer)
  6. uncompress(final byte[] src)
  7. uncompressByte(byte[] content)
  8. uncompressByteArray(byte[] ubytes, String type)
  9. uncompressByteArray(byte[] xmlByteArray)