List of usage examples for java.util.zip Inflater inflate
public int inflate(ByteBuffer output) throws DataFormatException
From source file:com.ctriposs.r2.filter.compression.DeflateCompressor.java
@Override public byte[] inflate(InputStream data) throws CompressionException { byte[] input; try {//from w ww . j a v a 2 s . co m input = IOUtils.toByteArray(data); } catch (IOException e) { throw new CompressionException(CompressionConstants.DECODING_ERROR + CompressionConstants.BAD_STREAM, e); } Inflater zlib = new Inflater(); zlib.setInput(input); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] temp = new byte[CompressionConstants.BUFFER_SIZE]; int bytesRead; while (!zlib.finished()) { try { bytesRead = zlib.inflate(temp); } catch (DataFormatException e) { throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName(), e); } if (bytesRead == 0) { if (!zlib.needsInput()) { throw new CompressionException(CompressionConstants.DECODING_ERROR + getContentEncodingName()); } else { break; } } if (bytesRead > 0) { output.write(temp, 0, bytesRead); } } zlib.end(); return output.toByteArray(); }
From source file:org.getspout.spoutapi.packet.PacketSendPrecache.java
public void decompress() { if (compressed) { Inflater decompressor = new Inflater(); decompressor.setInput(fileData); ByteArrayOutputStream bos = new ByteArrayOutputStream(fileData.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { }/*from w w w .j a v a 2s . c om*/ } try { bos.close(); } catch (IOException e) { } fileData = bos.toByteArray(); } }
From source file:org.getspout.spout.packet.PacketCustomMultiBlockOverride.java
public void decompress() { if (compressed) { Inflater decompressor = new Inflater(); decompressor.setInput(data);//w ww. ja va 2 s . c om ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { } } try { bos.close(); } catch (IOException e) { } compressed = false; data = bos.toByteArray(); } }
From source file:org.getspout.spout.packet.PacketBlockData.java
public void decompress() { if (compressed) { Inflater decompressor = new Inflater(); decompressor.setInput(data);/*from www .j a v a 2 s . co m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { } } try { bos.close(); } catch (IOException e) { } data = bos.toByteArray(); } }
From source file:org.getspout.spoutapi.packet.PacketCustomMultiBlockOverride.java
@Override public void decompress() { if (compressed) { Inflater decompressor = new Inflater(); decompressor.setInput(data);// w w w . j a v a2 s.c om ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { } } try { bos.close(); } catch (IOException e) { } data = bos.toByteArray(); } }
From source file:org.getspout.spoutapi.packet.PacketBlockData.java
public void decompress() { if (compressed) { Inflater decompressor = new Inflater(); decompressor.setInput(data);/*from w w w .ja v a2s. c o m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { } } try { bos.close(); } catch (IOException e) { } data = bos.toByteArray(); } }
From source file:org.getspout.spoutapi.packet.PacketCacheFile.java
public void decompress() { if (compressed) { Inflater decompressor = new Inflater(); decompressor.setInput(fileData); ByteArrayOutputStream bos = new ByteArrayOutputStream(fileData.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { }/*from w ww.j a va 2 s .c o m*/ } try { bos.close(); } catch (IOException e) { } fileData = bos.toByteArray(); } }
From source file:org.apache.pdfbox.filter.FlateFilter.java
private ByteArrayOutputStream decompress(InputStream in) throws IOException, DataFormatException { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[2048]; int read = in.read(buf); if (read > 0) { Inflater inflater = new Inflater(); inflater.setInput(buf, 0, read); byte[] res = new byte[2048]; while (true) { int resRead = inflater.inflate(res); if (resRead != 0) { out.write(res, 0, resRead); continue; }//from w ww .j a v a2 s .co m if (inflater.finished() || inflater.needsDictionary() || in.available() == 0) { break; } read = in.read(buf); inflater.setInput(buf, 0, read); } } out.close(); return out; }
From source file:org.wso2.carbon.identity.sso.saml.util.SAMLSSOUtil.java
/** * Decoding and deflating the encoded AuthReq * * @param encodedStr encoded AuthReq//from www. j a v a 2 s . com * @return decoded AuthReq */ public static String decode(String encodedStr) throws IdentityException { try { org.apache.commons.codec.binary.Base64 base64Decoder = new org.apache.commons.codec.binary.Base64(); byte[] xmlBytes = encodedStr.getBytes("UTF-8"); byte[] base64DecodedByteArray = base64Decoder.decode(xmlBytes); try { Inflater inflater = new Inflater(true); inflater.setInput(base64DecodedByteArray); byte[] xmlMessageBytes = new byte[5000]; int resultLength = inflater.inflate(xmlMessageBytes); if (inflater.getRemaining() > 0) { throw new RuntimeException("didn't allocate enough space to hold " + "decompressed data"); } inflater.end(); String decodedString = new String(xmlMessageBytes, 0, resultLength, "UTF-8"); if (log.isDebugEnabled()) { log.debug("Request message " + decodedString); } return decodedString; } catch (DataFormatException e) { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(base64DecodedByteArray); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); InflaterInputStream iis = new InflaterInputStream(byteArrayInputStream); byte[] buf = new byte[1024]; int count = iis.read(buf); while (count != -1) { byteArrayOutputStream.write(buf, 0, count); count = iis.read(buf); } iis.close(); String decodedStr = new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8); if (log.isDebugEnabled()) { log.debug("Request message " + decodedStr, e); } return decodedStr; } } catch (IOException e) { throw new IdentityException("Error when decoding the SAML Request.", e); } }
From source file:org.getspout.spoutapi.packet.PacketCustomBlockChunkOverride.java
@Override public void decompress() { if (compressed && hasData) { Inflater decompressor = new Inflater(); decompressor.setInput(data);//from ww w. j a v a 2 s . c om ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length); byte[] buf = new byte[1024]; while (!decompressor.finished()) { try { int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { } } try { bos.close(); } catch (IOException e) { } data = bos.toByteArray(); } }