List of usage examples for java.util.zip DeflaterOutputStream DeflaterOutputStream
public DeflaterOutputStream(OutputStream out, boolean syncFlush)
From source file:org.resthub.rpc.AMQPHessianProxy.java
/** * Create the request message body//from w ww . j a va 2 s. com * @param method * @param args * @return * @throws IOException */ private byte[] createRequestBody(Method method, Object[] args) throws IOException { String methodName = method.getName(); if (_factory.isOverloadEnabled() && args != null && args.length > 0) { methodName = AbstractSkeleton.mangleName(method, false); } ByteArrayOutputStream payload = new ByteArrayOutputStream(256); OutputStream os; if (_factory.isCompressed()) { Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true); os = new DeflaterOutputStream(payload, deflater); } else { os = payload; } AbstractHessianOutput out = _factory.getHessianOutput(os); out.call(methodName, args); if (os instanceof DeflaterOutputStream) { ((DeflaterOutputStream) os).finish(); } out.flush(); return payload.toByteArray(); }
From source file:prz.PRZ.java
/** * * @param bytes//from w w w.j av a 2 s. c o m * @return */ public static byte[] deflate_test(byte[] bytes) { Deflater d = new Deflater(9, true); DeflaterOutputStream dfos; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { dfos = new DeflaterOutputStream(baos, d); dfos.write(bytes); dfos.finish(); byte[] y = baos.toByteArray(); System.out.println("LZHF-> BitLength:" + (bytes.length * 8) + "| BestLength: " + (y.length * 8) + "| Ratio: " + ((double) y.length / (bytes.length))); return y; } catch (IOException ex) { Logger.getLogger(PRZ.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:org.diorite.nbt.NbtOutputStream.java
/** * Create new nbt output stream for given file, and write nbt tag to it. * * @param tag nbt tag to write./*from w w w . j a v a 2 s .c o m*/ * @param file data file to be used. * @param def deflater to be used. * * @return created NbtOutputStream. * * @throws IOException if any write operation failed. */ public static NbtOutputStream writeDeflated(final NbtTag tag, final File file, final Deflater def) throws IOException { createFile(file); final NbtOutputStream out = new NbtOutputStream( new DeflaterOutputStream(new FileOutputStream(file, false), def)); out.write(tag); return out; }
From source file:com.vmware.demo.SamlService.java
public String generateSAMLRequest(String assertionConsumerServiceURL, String nameIdFormat) { String samlRequest = ""; try {// w w w .ja v a 2 s . co m // Generate ID String randId = "A71AB3E13"; // Create an issuer Object IssuerBuilder issuerBuilder = new IssuerBuilder(); Issuer issuer = issuerBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:assertion", "Issuer", "samlp"); issuer.setValue(issuerString); // Create NameIDPolicy NameIDPolicyBuilder nameIdPolicyBuilder = new NameIDPolicyBuilder(); NameIDPolicy nameIdPolicy = nameIdPolicyBuilder.buildObject(); if (StringUtils.isNotEmpty(nameIdFormat)) { nameIdPolicy.setFormat(nameIdFormat); } nameIdPolicy.setSPNameQualifier(issuerString); nameIdPolicy.setAllowCreate(true); // Create AuthnContextClassRef AuthnContextClassRefBuilder authnContextClassRefBuilder = new AuthnContextClassRefBuilder(); AuthnContextClassRef authnContextClassRef = authnContextClassRefBuilder .buildObject("urn:oasis:names:tc:SAML:2.0:assertion", "AuthnContextClassRef", "saml"); authnContextClassRef .setAuthnContextClassRef("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"); // Create RequestedAuthnContext RequestedAuthnContextBuilder requestedAuthnContextBuilder = new RequestedAuthnContextBuilder(); RequestedAuthnContext requestedAuthnContext = requestedAuthnContextBuilder.buildObject(); requestedAuthnContext.setComparison(AuthnContextComparisonTypeEnumeration.EXACT); requestedAuthnContext.getAuthnContextClassRefs().add(authnContextClassRef); AuthnRequestBuilder authRequestBuilder = new AuthnRequestBuilder(); AuthnRequest authRequest = authRequestBuilder.buildObject("urn:oasis:names:tc:SAML:2.0:protocol", "AuthnRequest", "samlp"); authRequest.setForceAuthn(false); authRequest.setIsPassive(false); authRequest.setIssueInstant(new DateTime()); authRequest.setProtocolBinding("urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"); authRequest.setAssertionConsumerServiceURL(assertionConsumerServiceURL); authRequest.setIssuer(issuer); authRequest.setNameIDPolicy(nameIdPolicy); authRequest.setRequestedAuthnContext(requestedAuthnContext); authRequest.setID(randId); authRequest.setVersion(SAMLVersion.VERSION_20); Marshaller marshaller = org.opensaml.Configuration.getMarshallerFactory().getMarshaller(authRequest); org.w3c.dom.Element authDOM = marshaller.marshall(authRequest); StringWriter rspWrt = new StringWriter(); XMLHelper.writeNode(authDOM, rspWrt); String messageXML = rspWrt.toString(); Deflater deflater = new Deflater(Deflater.DEFLATED, true); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater); deflaterOutputStream.write(messageXML.getBytes()); deflaterOutputStream.close(); samlRequest = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES); //samlRequest = URLEncoder.encode(samlRequest); logger.info("samlRequest: " + samlRequest); } catch (MarshallingException e) { logger.error("General Error", e); } catch (IOException e) { logger.error("General Error", e); } return samlRequest; }
From source file:org.wso2.carbon.apim.sso.Util.java
/** * @param xmlString String to be encoded * @return/* w w w .j a va 2s . com*/ */ public static String deflateAndEncode(String xmlString) throws Exception { Deflater deflater = new Deflater(Deflater.DEFLATED, true); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater); deflaterOutputStream.write(xmlString.getBytes()); deflaterOutputStream.close(); // Encoding the compressed message String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES); return encodedRequestMessage.trim(); }
From source file:ddf.security.samlp.SimpleSignTest.java
/** * Deflates a value and Base64 encodes the result. This code is copied from RestSecurity because it would cause a circular dependency to use it directly.. * * @param value value to deflate and Base64 encode * @return String//from w w w. java 2 s. c om * @throws IOException if the value cannot be converted */ public static String deflateAndBase64Encode(String value) throws IOException { ByteArrayOutputStream valueBytes = new ByteArrayOutputStream(); try (OutputStream tokenStream = new DeflaterOutputStream(valueBytes, new Deflater(Deflater.DEFLATED, true))) { tokenStream.write(value.getBytes(StandardCharsets.UTF_8)); tokenStream.close(); return new String(Base64.encodeBase64(valueBytes.toByteArray())); } }
From source file:org.socraticgrid.workbench.security.wso2.Saml2Util.java
/** * Compressing and Encoding the response * * @param xmlString String to be encoded * @return compressed and encoded String *///from w ww.ja v a 2 s. c o m public static String encode(String xmlString) throws Exception { Deflater deflater = new Deflater(Deflater.DEFLATED, true); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater); deflaterOutputStream.write(xmlString.getBytes()); deflaterOutputStream.close(); // Encoding the compressed message String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES); return encodedRequestMessage.trim(); }
From source file:org.wso2.carbon.identity.sso.saml.SAMLTestRequestBuilder.java
public static String encodeRequestMessage(RequestAbstractType requestMessage) throws MarshallingException, IOException, ConfigurationException { DefaultBootstrap.bootstrap();/*from w w w . j a v a2s .c om*/ System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(requestMessage); Element authDOM = null; authDOM = marshaller.marshall(requestMessage); /* Compress the message */ Deflater deflater = new Deflater(Deflater.DEFLATED, true); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater); StringWriter rspWrt = new StringWriter(); XMLHelper.writeNode(authDOM, rspWrt); deflaterOutputStream.write(rspWrt.toString().getBytes()); deflaterOutputStream.close(); /* Encoding the compressed message */ String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES); byteArrayOutputStream.write(byteArrayOutputStream.toByteArray()); byteArrayOutputStream.toString(); return encodedRequestMessage; }
From source file:org.apache.cloudstack.utils.auth.SAMLUtils.java
public static String encodeSAMLRequest(XMLObject authnRequest) throws MarshallingException, IOException { Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(authnRequest); Element authDOM = marshaller.marshall(authnRequest); StringWriter requestWriter = new StringWriter(); XMLHelper.writeNode(authDOM, requestWriter); String requestMessage = requestWriter.toString(); Deflater deflater = new Deflater(Deflater.DEFLATED, true); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, deflater); deflaterOutputStream.write(requestMessage.getBytes()); deflaterOutputStream.close();//from w w w. j av a 2s . c o m String encodedRequestMessage = Base64.encodeBytes(byteArrayOutputStream.toByteArray(), Base64.DONT_BREAK_LINES); encodedRequestMessage = URLEncoder.encode(encodedRequestMessage, HttpUtils.UTF_8).trim(); return encodedRequestMessage; }
From source file:org.diorite.impl.world.io.anvil.AnvilRegion.java
private NbtOutputStream getOutputStream(final int x, final int z, final byte version) throws IOException { this.checkBounds(x, z); if (version == VERSION_GZIP) { return new NbtOutputStream(new BufferedOutputStream(new GZIPOutputStream(new ChunkBuffer(x, z)))); }//from ww w. ja v a2s .co m if (version == VERSION_DEFLATE) { return new NbtOutputStream(new BufferedOutputStream( new DeflaterOutputStream(new ChunkBuffer(x, z), new Deflater(Deflater.BEST_SPEED)))); } throw new RuntimeException("Unknown version: " + version); }