List of usage examples for java.util.zip InflaterInputStream InflaterInputStream
public InflaterInputStream(InputStream in)
From source file:org.diorite.nbt.NbtInputStream.java
/** * Construct new NbtInputStream for inflated input stream and limiter. * * @param in input stream to be used. * @param limiter limiter to be used.//from w w w . j a va2 s .c o m * * @return new NbtInputStream. */ public static NbtInputStream fromInflated(final InputStream in, final NbtLimiter limiter) { return new NbtInputStream(new DataInputStream( new BufferedInputStream(new InflaterInputStream(new NbtInputLimitedStream(in, limiter))))); }
From source file:com.uber.hoodie.common.TestRawTripPayload.java
private String unCompressData(byte[] data) throws IOException { InflaterInputStream iis = new InflaterInputStream(new ByteArrayInputStream(data)); StringWriter sw = new StringWriter(dataSize); IOUtils.copy(iis, sw);// w ww . j a v a2 s. c o m return sw.toString(); }
From source file:org.droidparts.http.wrapper.DefaultHttpClientWrapper.java
public static InputStream getUnpackedInputStream(HttpEntity entity) throws HTTPException { try {/*from w w w . j a va 2 s .c o m*/ InputStream is = entity.getContent(); Header contentEncodingHeader = entity.getContentEncoding(); L.d(contentEncodingHeader); if (contentEncodingHeader != null) { String contentEncoding = contentEncodingHeader.getValue(); if (!isEmpty(contentEncoding)) { contentEncoding = contentEncoding.toLowerCase(); if (contentEncoding.contains("gzip")) { return new GZIPInputStream(is); } else if (contentEncoding.contains("deflate")) { return new InflaterInputStream(is); } } } return is; } catch (Exception e) { throw new HTTPException(e); } }
From source file:org.wso2.identity.integration.test.requestPathAuthenticator.RequestPathAuthenticatorInvalidUserTestCase.java
/** * Decoding and deflating the encoded AuthReq * * @param encodedStr encoded AuthReq// w ww. j av a 2s . co m * @return decoded AuthReq */ private static String decode(String encodedStr) { try { Base64 base64Decoder = new Base64(); byte[] xmlBytes = encodedStr.getBytes(DEFAULT_CHARSET); 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("End of the compressed data stream has NOT been reached"); } inflater.end(); String decodedString = new String(xmlMessageBytes, 0, resultLength, (DEFAULT_CHARSET)); 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); return decodedStr; } } catch (IOException e) { Assert.fail("Error while decoding SAML response", e); return ""; } }
From source file:de.tntinteractive.portalsammler.engine.SecureStore.java
private static Pair<Integer, MapReader> createMapReader(final InputStream stream, final SecureRandom srand, final byte[] key) throws IOException { final InputStream cipher = CryptoHelper.createAesDecryptStream(stream, key, srand); final int salt = readInt(cipher); final InflaterInputStream inflate = new InflaterInputStream(cipher); return Pair.of(salt, MapReader.createFrom(inflate)); }
From source file:com.gargoylesoftware.htmlunit.WebResponseData.java
private InputStream getStream(final DownloadedContent downloadedContent, final List<NameValuePair> headers) throws IOException { InputStream stream = downloadedContent_.getInputStream(); if (stream == null) { return null; }/*from www . j a v a 2 s . com*/ if (downloadedContent.isEmpty()) { return stream; } final String encoding = getHeader(headers, "content-encoding"); if (encoding != null) { if (StringUtils.contains(encoding, "gzip")) { stream = new GZIPInputStream(stream); } else if (StringUtils.contains(encoding, "deflate")) { boolean zlibHeader = false; if (stream.markSupported()) { // should be always the case as the content is in a byte[] or in a file stream.mark(2); final byte[] buffer = new byte[2]; stream.read(buffer, 0, 2); zlibHeader = (((buffer[0] & 0xff) << 8) | (buffer[1] & 0xff)) == 0x789c; stream.reset(); } if (zlibHeader) { stream = new InflaterInputStream(stream); } else { stream = new InflaterInputStream(stream, new Inflater(true)); } } } return stream; }
From source file:ubicrypt.core.remote.RemoteRepository.java
@Override public Observable<InputStream> get(final UbiFile file) { return inboundQueue.call(fileGetter .call(file,/*from ww w . ja v a 2 s .c o m*/ (rfile, is) -> new MonitorInputStream( new InflaterInputStream(AESGCM.decryptIs(rfile.getKey().getBytes(), is)))) .cast(MonitorInputStream.class).flatMap(is -> create(subscriber -> { final FileProvenience fp = new FileProvenience(file, this); is.monitor().subscribe(chunk -> progressEvents.onNext(new ProgressFile(fp, chunk)), err -> { Utils.logError.call(err); progressEvents.onNext(new ProgressFile(fp, false, true)); subscriber.onError(err); Utils.close(is); }, () -> { progressEvents.onNext(new ProgressFile(fp, true, false)); subscriber.onCompleted(); Utils.close(is); }); subscriber.onNext(is); }))); }
From source file:servlets.ProcessResponseServlet.java
private String decodeAuthnRequestXML(String encodedRequestXmlString) throws SamlException { try {// ww w . ja v a 2s . com // URL decode // No need to URL decode: auto decoded by request.getParameter() method // Base64 decode Base64 base64Decoder = new Base64(); byte[] xmlBytes = encodedRequestXmlString.getBytes("UTF-8"); byte[] base64DecodedByteArray = base64Decoder.decode(xmlBytes); //Uncompress the AuthnRequest data //First attempt to unzip the byte array according to DEFLATE (rfc 1951) try { 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"); } inflater.end(); return new String(xmlMessageBytes, 0, resultLength, "UTF-8"); } catch (DataFormatException e) { // if DEFLATE fails, then attempt to unzip the byte array according to // zlib (rfc 1950) 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(); return new String(baos.toByteArray()); } } catch (UnsupportedEncodingException e) { throw new SamlException("Error decoding AuthnRequest: " + "Check decoding scheme - " + e.getMessage()); } catch (IOException e) { throw new SamlException("Error decoding AuthnRequest: " + "Check decoding scheme - " + e.getMessage()); } }
From source file:Comman.Tool.java
public String String_decompress(byte[] bytes) { InputStream in = new InflaterInputStream(new ByteArrayInputStream(bytes)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {// www .ja v a 2 s . c om byte[] buffer = new byte[8192]; int len; while ((len = in.read(buffer)) > 0) { baos.write(buffer, 0, len); } return new String(baos.toByteArray(), "UTF-8"); } catch (IOException e) { throw new AssertionError(e); } }
From source file:com.irusist.xiaoao.turntable.service.RequestService.java
/** * ?/*from www . j av a 2 s .com*/ * * @param account * ?? * @param token * oauth?token */ private void request(String account, String token) { HttpClient client = new DefaultHttpClient(); HttpPost method = new HttpPost(getUrl()); method.addHeader("Connection", "close"); method.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); // method.addHeader("User-Agent", Constants.USER_AGENT); method.addHeader("User-Agent", Constants.USER_AGENT_IPHONE); Map<String, String> params = getCommonParams(token); params.putAll(getParams()); List<NameValuePair> body = new ArrayList<NameValuePair>(); for (Map.Entry<String, String> entry : params.entrySet()) { body.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } InputStream inputStream = null; try { HttpEntity entity = new UrlEncodedFormEntity(body, Constants.DEFAULT_ENCODING); method.setEntity(entity); HttpResponse response = client.execute(method); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { StringBuilder output = new StringBuilder(); output.append("?: ").append(account).append(",: "); inputStream = new InflaterInputStream(response.getEntity().getContent()); byte[] data = new byte[1024]; int len; while ((len = inputStream.read(data)) != -1) { output.append(new String(data, 0, len)); } System.out.println(output.toString()); } else { System.out.println(""); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (Exception e) { e.printStackTrace(); } } } }