List of usage examples for java.util.zip DeflaterOutputStream DeflaterOutputStream
public DeflaterOutputStream(OutputStream out)
From source file:com.eviware.soapui.impl.wsdl.support.CompressionSupport.java
private static byte[] DeflaterCompress(byte[] requestContent) throws IOException { ByteArrayOutputStream compressedContent = new ByteArrayOutputStream(); DeflaterOutputStream defstream = new DeflaterOutputStream(compressedContent); defstream.write(requestContent);//w w w.ja va 2 s .c o m defstream.finish(); // get the compressed content return compressedContent.toByteArray(); }
From source file:com.autonomy.aci.client.transport.impl.AbstractEncryptionCodec.java
/** * Deflates the passed in <tt>String</tt> and prefixes the result with <tt>AUTN:</tt> before returning. * @param bytes The byte array to deflate * @return The deflated string prefixed with <tt>AUTN:</tt> as a byte array * @throws EncryptionCodecException If an error occurred during processing *//* w w w . j a v a2 s . com*/ protected byte[] deflateInternal(final byte[] bytes) throws EncryptionCodecException { LOGGER.trace("deflateInternal() called..."); // This is what will deflate for us... DeflaterOutputStream deflater = null; try { // Create the output container... final ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Create the deflater... deflater = new DeflaterOutputStream(baos); LOGGER.debug("Deflating content..."); // Deflate the input string... deflater.write(bytes); deflater.finish(); // Get the deflated bytes... final byte[] deflated = baos.toByteArray(); LOGGER.debug("Adding prefix to deflated content..."); // Get The deflated array prefix of AUTN: in bytes... final byte[] prefix = "AUTN:".getBytes("UTF-8"); // Copy both the prefix and the deflated query string into a new array... final byte[] toEncrypt = new byte[prefix.length + deflated.length]; System.arraycopy(prefix, 0, toEncrypt, 0, prefix.length); System.arraycopy(deflated, 0, toEncrypt, prefix.length, deflated.length); LOGGER.debug("Returning deflated and prefixed string..."); // Return the deflated query string... return toEncrypt; } catch (final IOException ioe) { throw new EncryptionCodecException("Unable to deflate the input.", ioe); } finally { IOUtils.getInstance().closeQuietly(deflater); } }
From source file:org.diorite.nbt.NbtOutputStream.java
/** * Create new deflated nbt output stream for given stream, and write nbt tag to it. * * @param tag nbt tag to write. * @param outputStream output stream to be used. * * @return created NbtOutputStream./*from ww w .j a va2 s.c om*/ * * @throws IOException if any write operation failed. */ public static NbtOutputStream writeDeflated(final NbtTag tag, final OutputStream outputStream) throws IOException { final NbtOutputStream out = new NbtOutputStream(new DeflaterOutputStream(outputStream)); out.write(tag); return out; }
From source file:org.openvpms.report.jasper.JRXMLDocumentHandler.java
/** * Creates a new {@link Document} from a stream. * * @param name the document name// ww w . j ava 2 s. co m * @param stream a stream representing the document content * @param mimeType the mime type of the document. May be {@code null} * @param size the size of stream * @return a new document * @throws DocumentException if the document can't be created * @throws ArchetypeServiceException for any archetype service error * @throws JRXMLDocumentException if the document version cannot be parsed */ public Document create(String name, InputStream stream, String mimeType, int size) { Document document; JasperDesign design; try { design = JRXmlLoader.load(stream); } catch (JRException exception) { if (ExceptionUtils.getRootCause(exception) instanceof SAXParseException) { if (name == null) { name = "file"; } throw new JRXMLDocumentException(exception, JRXMLDocumentException.ErrorCode.ReadError, name); } else { throw new DocumentException(DocumentException.ErrorCode.ReadError, exception, name); } } try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DeflaterOutputStream output = new DeflaterOutputStream(bytes); JRXmlWriter.writeReport(design, output, "UTF-8"); output.close(); document = create(name, bytes.toByteArray(), "text/xml", size); } catch (Exception exception) { throw new DocumentException(DocumentException.ErrorCode.WriteError, exception, name); } return document; }
From source file:Comman.Tool.java
public byte[] String_compress(String text) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/*from w ww . ja v a2 s . c om*/ try (OutputStream out = new DeflaterOutputStream(baos)) { out.write(text.getBytes("UTF-8")); } } catch (IOException e) { throw new AssertionError(e); } return baos.toByteArray(); }
From source file:com.linkedin.r2.filter.compression.stream.TestStreamingCompression.java
@Test public void testDeflateCompressor() throws IOException, InterruptedException, CompressionException, ExecutionException { StreamingCompressor compressor = new DeflateCompressor(_executor); final byte[] origin = new byte[BUF_SIZE]; Arrays.fill(origin, (byte) 'c'); ByteArrayOutputStream out = new ByteArrayOutputStream(); DeflaterOutputStream zlib = new DeflaterOutputStream(out); IOUtils.write(origin, zlib);/*from ww w . java 2 s .c om*/ zlib.close(); byte[] compressed = out.toByteArray(); testCompress(compressor, origin, compressed); testDecompress(compressor, origin, compressed); testCompressThenDecompress(compressor, origin); }
From source file:gov.nasa.ensemble.common.CommonUtils.java
public static byte[] compress(byte[] input) { try {/*from w w w. j a va 2 s . c om*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); DeflaterOutputStream dos = new DeflaterOutputStream(baos); dos.write(input); dos.close(); return baos.toByteArray(); } catch (IOException e) { throw new Error(e); } }
From source file:de.mpg.escidoc.services.fledgeddata.webservice.oaiServlet.java
/** * Get a response Writer depending on acceptable encodings * @param request the servlet's request information * @param response the servlet's response information * @exception IOException an I/O error occurred *//*from w ww. j av a2 s .c o m*/ public static Writer getWriter(HttpServletRequest request, HttpServletResponse response) throws IOException { Writer out; String encodings = request.getHeader("Accept-Encoding"); if (encodings != null && encodings.indexOf("gzip") != -1) { response.setHeader("Content-Encoding", "gzip"); out = new OutputStreamWriter(new GZIPOutputStream(response.getOutputStream()), "UTF-8"); } else if (encodings != null && encodings.indexOf("deflate") != -1) { response.setHeader("Content-Encoding", "deflate"); out = new OutputStreamWriter(new DeflaterOutputStream(response.getOutputStream()), "UTF-8"); } else { out = response.getWriter(); } return out; }
From source file:com.cloud.agent.api.SecurityIngressRulesCmd.java
public String compressStringifiedRules() { StringBuilder ruleBuilder = new StringBuilder(); for (SecurityIngressRulesCmd.IpPortAndProto ipPandP : getRuleSet()) { ruleBuilder.append(ipPandP.getProto()).append(":").append(ipPandP.getStartPort()).append(":") .append(ipPandP.getEndPort()).append(":"); for (String cidr : ipPandP.getAllowedCidrs()) { ruleBuilder.append(cidr).append(","); }/*from www. ja v a 2 s .co m*/ ruleBuilder.append("NEXT"); ruleBuilder.append(" "); } String stringified = ruleBuilder.toString(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { //Note : not using GZipOutputStream since that is for files //GZipOutputStream gives a different header, although the compression is the same DeflaterOutputStream dzip = new DeflaterOutputStream(out); dzip.write(stringified.getBytes()); dzip.close(); } catch (IOException e) { s_logger.warn("Exception while compressing ingress rules"); return null; } return Base64.encodeBase64String(out.toByteArray()); }
From source file:org.diorite.nbt.NbtOutputStream.java
/** * Create new deflated nbt output stream for given file, and write nbt tag to it. * * @param tag nbt tag to write.//from w w w . ja v a 2 s . co m * @param file data file to be used. * * @return created NbtOutputStream. * * @throws IOException if any write operation failed. */ public static NbtOutputStream writeDeflated(final NbtTag tag, final File file) throws IOException { createFile(file); final NbtOutputStream out = new NbtOutputStream( new DeflaterOutputStream(new FileOutputStream(file, false))); out.write(tag); return out; }