/*
@see
com.ibm.wsspi.http.channel.compression.DecompressionHandler#decompress(
com.ibm.wsspi.bytebuffer.WsByteBuffer)
12929
@SuppressWarnings("unused")
    public List<WsByteBuffer> decompress(WsByteBuffer buffer) throws DataFormatException {
        List<WsByteBuffer> output = new LinkedList<WsByteBuffer>();
        output.add(buffer);
        this.size += buffer.remaining();
        return output;
    }
1126932
public HttpResponse decompress() throws IOException {
    String enc = header("Content-Encoding");
    return (enc != null && enc.contains("gzip")) ? unzip() : this;
  }
1255749
public byte decodeBuffer(InputStream in)[] throws IOException {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        decodeBuffer(in, outStream);
        return (outStream.toByteArray());
    }
1292274
public static void decompressOneBlock(int[] decompBlock, int[] inBlock,
                int blockSize) {
                int expNum = inBlock[0] & MASK[31 - POSSIBLE_B_BITS];
                int bits = (inBlock[0] >>> (31 - POSSIBLE_B_BITS)) & (0x1f);

                int[] expPosBuffer = new int[blockSize];
                int[] expHighBitsBuffer = new int[blockSize];

                // decompress the b-bit slots
                int offset = HEADER_SIZE;
                int compressedBits = 0;
                if (bits == 0) {
                        Arrays.fill(decompBlock, 0);
                } else {
                        compressedBits = decompressBBitSlots(decompBlock,
                                inBlock, blockSize, bits);
                        // compressedBits =
                        // decompressBBitSlotsWithHardCodes(decompBlock,
                        // inBlock, blockSize, bits);
                }
                offset += compressedBits;

                // decompress exceptions
                if (expNum > 0) {
                        compressedBits = decompressBlockByS16(expPosBuffer,
                                inBlock, offset, expNum);
                        offset += compressedBits;
                        compressedBits = decompressBlockByS16(
                                expHighBitsBuffer, inBlock, offset, expNum);
                        offset += compressedBits;

                        for (int i = 0; i < expNum; i++) {
                                int curExpPos = expPosBuffer[i];
                                int curHighBits = expHighBitsBuffer[i];
                                decompBlock[curExpPos] = (decompBlock[curExpPos] & MASK[bits])
                                        | ((curHighBits & MASK[32 - bits]) << bits);
                        }
                }
        }
222623
public static void decompress(File file, boolean delete) throws Exception {
		FileInputStream fis = new FileInputStream(file);
		FileOutputStream fos = new FileOutputStream(file.getPath().replace(EXT, ""));
		decompress(fis, fos);
		fis.close();
		fos.flush();
		fos.close();
		if (delete) {
			file.delete();
		}
	}
389910
@Override
    synchronized public int encodeIntoCompressedByteBuffer(
            final ByteBuffer targetBuffer,
            final int compressionLevel) {
        int neededCapacity = getNeededByteBufferCapacity(countsArrayLength);
        if (intermediateUncompressedByteBuffer == null || intermediateUncompressedByteBuffer.capacity() < neededCapacity) {
            intermediateUncompressedByteBuffer = ByteBuffer.allocate(neededCapacity).order(BIG_ENDIAN);
        }
        intermediateUncompressedByteBuffer.clear();
        int initialTargetPosition = targetBuffer.position();

        final int uncompressedLength = encodeIntoByteBuffer(intermediateUncompressedByteBuffer);
        targetBuffer.putInt(getCompressedEncodingCookie());

        targetBuffer.putInt(0); // Placeholder for compressed contents length

        Deflater compressor = new Deflater(compressionLevel);
        compressor.setInput(intermediateUncompressedByteBuffer.array(), 0, uncompressedLength);
        compressor.finish();

        byte[] targetArray;

        if (targetBuffer.hasArray()) {
            targetArray = targetBuffer.array();
        } else {
            if (intermediateUncompressedByteArray == null ||
                intermediateUncompressedByteArray.length < targetBuffer.capacity()) {
                intermediateUncompressedByteArray = new byte[targetBuffer.capacity()];
            }
            targetArray = intermediateUncompressedByteArray;
        }

        int compressedTargetOffset = initialTargetPosition + 8;
        int compressedDataLength =
            compressor.deflate(
                targetArray,
                compressedTargetOffset,
                targetArray.length - compressedTargetOffset
            );
        compressor.end();

        if (!targetBuffer.hasArray()) {
            targetBuffer.put(targetArray, compressedTargetOffset, compressedDataLength);
        }

        targetBuffer.putInt(initialTargetPosition + 4, compressedDataLength); // Record the compressed length
        int bytesWritten = compressedDataLength + 8;
        targetBuffer.position(initialTargetPosition + bytesWritten);
        return bytesWritten;
    }
374549
public static File compress(CompressionMethod _method, String _sourceFile, String _outputFileName) {
    	if (_method == null || _sourceFile == null) {
    		return null;
    	}

        File inputFile = new File(_sourceFile);

        if (!inputFile.exists()) {
            return null;
        }

        byte[] buffer = new byte[1024];
        try {
        	Constructor<? extends DeflaterOutputStream> constructor = _method.getOutputStreamClass().getConstructor(OutputStream.class);
        	if (constructor != null) {
        		DeflaterOutputStream compressOutputStream = constructor.newInstance(new FileOutputStream(_outputFileName));
	            try (FileInputStream in = new FileInputStream(_sourceFile)) {
	                int len;
	                while ((len = in.read(buffer)) > 0) {
	                    compressOutputStream.write(buffer, 0, len);
	                }

	                in.close();

	                compressOutputStream.finish();
	                compressOutputStream.close();
	                return new File(_outputFileName);
	            }
        	}
        } catch (IOException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException _ex) {
            LOGGER.error("Cannot uncompress file: ", _ex);
        }
        return null;

    }
247522
protected void decompressData(HashMap m) {

        for (Object key : m.keySet()) {
            if (m.get(key) instanceof ArrayList) {
                // iterate sub array nodes
                decompressData((ArrayList) m.get(key));
            } else if (m.get(key) instanceof HashMap) {
                // iterate sub data nodes
                decompressData((HashMap) m.get(key));
            } else {
                // ignore other type nodes
            }
        }

    }
1010160
public static byte[] decompressFast(byte[] src, int srcOffset, int exactDecompressedSize) {
        if (src == null) {
            throw new IllegalArgumentException("src must not be null.");
        }

        if (srcOffset < 0) {
            throw new IllegalArgumentException("srcOffset must equal to or larger than 0 but " + srcOffset);
        }

        if (exactDecompressedSize < 0) {
            throw new IllegalArgumentException("exactDecompressedSize must equal to or larger than 0 but " + exactDecompressedSize);
        }

        LZ4FastDecompressor decompressor = factory.fastDecompressor();

        return decompressor.decompress(src, srcOffset, exactDecompressedSize);
    }
1317717
public static void copyBuffer(WsByteBuffer src, WsByteBuffer dst) {
        copyBuffer(src, dst, src.remaining());
    }
975629
public void compress(ByteBuffer src, ByteBuffer dest) {
    final int compressedLength = compress(src, src.position(), src.remaining(), dest, dest.position(), dest.remaining());
    src.position(src.limit());
    dest.position(dest.position() + compressedLength);
  }
989627
@SneakyThrows
    public static String decompress(final String zippedBase64Str) {
        val bytes = EncodingUtils.decodeBase64(zippedBase64Str);
        try (val zi = new GZIPInputStream(new ByteArrayInputStream(bytes))) {
            return IOUtils.toString(zi, Charset.defaultCharset());
        }
    }
691892
public RawResponse decompress(boolean decompress) {
        return new RawResponse(method, url, statusCode, statusLine, cookies, headers, body, charset, decompress);
    }
26372
public static void compress(InputStream is, OutputStream os) throws Exception {
		GZIPOutputStream gos = new GZIPOutputStream(os);
		int count;
		byte data[] = new byte[BUFFER];
		while ((count = is.read(data, 0, BUFFER)) != -1) {
			gos.write(data, 0, count);
		}
		gos.finish();
		gos.flush();
		gos.close();
	}
75746
@Override
public synchronized void  close() throws IOException {
try {
   if (bbr != null) {
        bbr.close();
      }
    } finally {
      if (decompressor != null) {
        CodecPool.returnDecompressor(decompressor);
        decompressor = null;
      }
    }
  }
1287919
public static byte[] deflater(final byte[] inputByte) throws IOException {
		int compressedDataLength = 0;
		Deflater compresser = new Deflater();
		compresser.setInput(inputByte);
		compresser.finish();
		ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length);
		byte[] result = new byte[1024];
		try {
			while (!compresser.finished()) {
				compressedDataLength = compresser.deflate(result);
				o.write(result, 0, compressedDataLength);
			}
		} finally {
			o.close();
		}
		compresser.end();
		return o.toByteArray();
	}
373072
public static String decompressFromBase64String(String compressed) throws IOException {
        return decompressString(Base64.decode(compressed.getBytes(StandardCharsets.UTF_8)));
    }