List of usage examples for java.util.zip Inflater end
public void end()
From source file:Main.java
public static byte[] decompress(byte[] data, int off, int len) { byte[] output = null; Inflater decompresser = new Inflater(); decompresser.reset();//from ww w .ja v a 2 s . com decompresser.setInput(data, off, len); ByteArrayOutputStream out = new ByteArrayOutputStream(data.length); try { byte[] result = new byte[1024]; while (!decompresser.finished()) { int i = decompresser.inflate(result); out.write(result, 0, i); } output = out.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { out.close(); } catch (Exception e) { } decompresser.end(); } return output; }
From source file:org.apache.tez.common.TezCommonUtils.java
@Private public static byte[] decompressByteStringToByteArray(ByteString byteString) throws IOException { Inflater inflater = newInflater(); try {//from ww w. ja v a 2 s.c o m return decompressByteStringToByteArray(byteString, inflater); } finally { inflater.end(); } }
From source file:org.socraticgrid.workbench.security.wso2.Saml2Util.java
/** * Decoding and deflating the encoded AuthReq * * @param encodedStr encoded AuthReq/*from ww w . ja v a2 s . co m*/ * @return decoded AuthReq */ public static String decode(String encodedStr) throws Exception { 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.finished()) { throw new RuntimeException("didn't allocate enough space to hold " + "decompressed data"); } inflater.end(); return new String(xmlMessageBytes, 0, resultLength, "UTF-8"); } catch (DataFormatException e) { ByteArrayInputStream bais = new ByteArrayInputStream(base64DecodedByteArray); ByteArrayOutputStream baos = new ByteArrayOutputStream(); InflaterInputStream iis = new InflaterInputStream(bais); byte[] buf = new byte[1024]; int count = iis.read(buf); while (count != -1) { baos.write(buf, 0, count); count = iis.read(buf); } iis.close(); String decodedStr = new String(baos.toByteArray()); return decodedStr; } } catch (IOException e) { throw new Exception("Error when decoding the SAML Request.", e); } }
From source file:com.hundsun.jresplus.web.nosession.cookie.HessianZipSerializer.java
public static Object decode(byte[] encodedValue) throws SerializationException { ByteArrayInputStream bais = new ByteArrayInputStream(encodedValue); Inflater inf = new Inflater(false); InflaterInputStream iis = new InflaterInputStream(bais, inf); Hessian2Input hi = null;/*from ww w. j a v a 2s . c o m*/ try { hi = new Hessian2Input(iis); return hi.readObject(); } catch (Exception e) { throw new SerializationException("Failed to parse data", e); } finally { if (hi != null) { try { hi.close(); } catch (IOException e) { } } try { iis.close(); } catch (IOException e) { } inf.end(); } }
From source file:Main.java
public static byte[] decompress(byte[] data, int off, int len) { byte[] output = null; Inflater decompresser = new Inflater(); decompresser.reset();/*from w w w . j a v a2 s . c o m*/ // decompresser.setInput(data); decompresser.setInput(data, off, len); ByteArrayOutputStream o = new ByteArrayOutputStream(data.length); try { byte[] buf = new byte[1024]; while (!decompresser.finished()) { int i = decompresser.inflate(buf); o.write(buf, 0, i); } output = o.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { o.close(); decompresser.end(); } catch (Exception e) { } } return output; }
From source file:ch.cern.security.saml2.utils.xml.XMLUtils.java
public static String xmlDecodeAndInflate(String encodedXmlString, boolean isDebugEnabled) throws UnsupportedEncodingException, DataFormatException { // URL decode // No need to URL decode: auto decoded by request.getParameter() method (GET) if (isDebugEnabled) nc.notice("Encoded XML String: " + encodedXmlString); // Base64 decode Base64 base64Decoder = new Base64(); byte[] xmlBytes = encodedXmlString.getBytes("UTF-8"); byte[] base64DecodedByteArray = base64Decoder.decode(xmlBytes); if (isDebugEnabled) nc.notice("Base64 decoded bytes: " + new String(base64DecodedByteArray, "UTF-8")); // Inflate (uncompress) the AuthnRequest data // First attempt to unzip the byte array according to DEFLATE (rfc 1951) Inflater inflater = new Inflater(true); inflater.setInput(base64DecodedByteArray); // since we are decompressing, it's impossible to know how much space we // might need; hopefully this number is suitably big byte[] xmlMessageBytes = new byte[5000]; int resultLength = inflater.inflate(xmlMessageBytes); if (!inflater.finished()) { throw new RuntimeException("didn't allocate enough space to hold " + "decompressed data"); }/*ww w . j a v a 2 s.c om*/ inflater.end(); String decodedString = new String(xmlMessageBytes, 0, resultLength, "UTF-8"); if (isDebugEnabled) nc.notice("Decoded and inflated string (UTF-8): " + new String(base64DecodedByteArray)); return decodedString; }
From source file:gov.niem.ws.util.SecurityUtil.java
/** * Decode data by Base64 decoding, then decompressing with the DEFLATE * algorithm; reverses encodeHeader./*ww w. java2 s. c o m*/ * * @param encoded * @return the decoded, decompressed data * @throws DataFormatException */ public static String decodeHeader(byte[] encoded) throws DataFormatException { // TODO: length limit on encoded? byte[] compressedBytes = Base64.decodeBase64(encoded); ByteArrayOutputStream out = new ByteArrayOutputStream(compressedBytes.length); Inflater inflater = new Inflater(); inflater.setInput(compressedBytes); byte[] buffer = new byte[1024]; while (!inflater.finished()) { int count = inflater.inflate(buffer); if (count == 0) break; out.write(buffer, 0, count); } try { inflater.end(); out.close(); } catch (IOException e) { } return new String(out.toByteArray()); }
From source file:Main.java
/** * Decompress the zlib-compressed bytes and return an array of decompressed * bytes//from ww w .java 2 s . co m * */ public static byte[] decompress(byte compressedBytes[]) throws DataFormatException { Inflater decompresser = new Inflater(); decompresser.setInput(compressedBytes); byte[] resultBuffer = new byte[compressedBytes.length * 2]; byte[] resultTotal = new byte[0]; int resultLength = decompresser.inflate(resultBuffer); while (resultLength > 0) { byte previousResult[] = resultTotal; resultTotal = new byte[resultTotal.length + resultLength]; System.arraycopy(previousResult, 0, resultTotal, 0, previousResult.length); System.arraycopy(resultBuffer, 0, resultTotal, previousResult.length, resultLength); resultLength = decompresser.inflate(resultBuffer); } decompresser.end(); return resultTotal; }
From source file:Main.java
public static byte[] decompress(byte[] data, int off, int len, int srcLen) { byte[] output = null; Inflater decompresser = new Inflater(); decompresser.reset();/* w ww. j ava 2 s . c om*/ // decompresser.setInput(data); decompresser.setInput(data, off, len); ByteArrayOutputStream o = new ByteArrayOutputStream(srcLen); try { o.reset(); byte[] buf = new byte[1024]; while (!decompresser.finished()) { int i = decompresser.inflate(buf); o.write(buf, 0, i); } output = o.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { o.close(); decompresser.end(); } catch (Exception e) { } } return output; }
From source file:Main.java
public final static byte[] decompress(byte[] input) throws IOException { if (input == null || input.length == 0) { return input; }/*from www .jav a 2 s. c om*/ Inflater inflator = new Inflater(); inflator.setInput(input); ByteArrayOutputStream bin = new ByteArrayOutputStream(input.length); byte[] buf = new byte[BUFFER_SIZE]; try { while (true) { int count = inflator.inflate(buf); if (count > 0) { bin.write(buf, 0, count); } else if (count == 0 && inflator.finished()) { break; } else { throw new IOException("bad zip data, size:" + input.length); } } } catch (DataFormatException t) { throw new IOException(t); } finally { inflator.end(); } return bin.toByteArray(); }