Package java.util.zip

Examples of java.util.zip.GZIPOutputStream


                    SerializeAdapter adpt = adapters[i];
                    try
                    {
                        if ( runs == 1 || runs == 3 )
                        {
                            DeflaterOutputStream sOut = new GZIPOutputStream( bOut, EJConstants.BUFFERED_STREAM_SIZE )
                                {
                                    {
                                        def.setLevel( EJConstants.DEFAULT_COMPRESSION_LEVEL );
                                    }
                                };
                            adpt.write( new ObjectBean(), sOut );
                            sOut.finish();
                            sOut.close();
                        }
                        else
                        {
                            adpt.write( new ObjectBean(), bOut );
                        }
View Full Code Here


        logger.log( Level.FINEST, "Using compression: " + compressed );
        boolean flushed = false;

        if ( compressed )
        {
            GZIPOutputStream sOut = new GZIPOutputStream( out, EJConstants.BUFFERED_STREAM_SIZE )
                {
                    {
                        def.setLevel( compressionLevel );
                    }
                };

            adapter.write( obj, new UncloseableOutputStream( sOut, adapter.requiresCustomEOFHandling() ) );

            sOut.finish();
            flushed = true;
        }
        else if ( !adapter.isSelfBuffered() )
        {
            OutputStream sOut = new UncloseableOutputStream(
                                                             new FastBufferedOutputStream(
                                                                                           out,
                                                                                           EJConstants.BUFFERED_STREAM_SIZE ) );
            adapter.write( obj, sOut );
            sOut.flush();
            flushed = true;
        }
        else
        {
            adapter.write( obj, new UncloseableOutputStream( out, adapter.requiresCustomEOFHandling() ) );
View Full Code Here

     
      if (log.isDebugEnabled()) {
        log.debug("Save state on client");     
      }
     
      GZIPOutputStream zos = null;
      ObjectOutputStream oos = null;
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      zos = new GZIPOutputStream(bos);
      oos = new ObjectOutputStream(zos);
      oos.writeObject(view.getStructure());
      oos.writeObject(view.getState());
      oos.close();
      zos.close();
      String valueToWrite = (new String(Base64.encodeBase64(bos.toByteArray()),"ISO-8859-1"));
      if (log.isTraceEnabled()) {
        log.trace("Saving on client side : " + valueToWrite);
      }
      writer.writeAttribute("value",valueToWrite, null);
View Full Code Here

    super();
    closed = false;
    this.response = response;
    this.servletStream = response.getOutputStream();
    byteStream = new ByteArrayOutputStream();
    gzipStream = new GZIPOutputStream(byteStream);
  }
View Full Code Here

    zippedData.remove(virtualId);
  }

  protected void pageOut(JRVirtualizable o) throws IOException {
    if (!zippedData.containsKey(o.getUID())) {
      GZIPOutputStream gos = null;
      try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(3000);
        gos = new GZIPOutputStream(baos);
        writeData(o, gos);
        gos.finish();
        gos.flush();

        byte[] data = baos.toByteArray();
        zippedData.put(o.getUID(), data);
      }
      finally {
        if (gos != null) {
          gos.close();
        }
      }
    }
    else {
      if (!isReadOnly(o)) {
View Full Code Here

     * @return the compressed byte array
     * @throws IOException if an excption occurs
     */
  static byte[] compress(byte[] data) throws IOException {
      ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
      GZIPOutputStream out = new GZIPOutputStream(bos);
     
        out.write(data);
        out.close();
        return bos.toByteArray();
    }
View Full Code Here

                        TemplateEngine.writeTemplate(fis, o1, templatePatterns, ASCII.getBytes("-UNRESOLVED_PATTERN-"));
                        fis.close();
                        final ByteBuffer o = new ByteBuffer();

                        if (zipContent) {
                            GZIPOutputStream zippedOut = new GZIPOutputStream(o);
                            ServerSideIncludes.writeSSI(o1, zippedOut, realmProp, clientIP);
                            //httpTemplate.writeTemplate(fis, zippedOut, tp, "-UNRESOLVED_PATTERN-".getBytes("UTF-8"));
                            zippedOut.finish();
                            zippedOut.flush();
                            zippedOut.close();
                            zippedOut = null;
                        } else {
                            ServerSideIncludes.writeSSI(o1, o, realmProp, clientIP);
                            //httpTemplate.writeTemplate(fis, o, tp, "-UNRESOLVED_PATTERN-".getBytes("UTF-8"));
                        }
                        if (method.equals(HeaderFramework.METHOD_HEAD)) {
                            HTTPDemon.sendRespondHeader(conProp, out,
                                    httpVersion, 200, null, mimeType, o.length(),
                                    targetDate, null, (templatePatterns == null) ? new ResponseHeader() : templatePatterns.getOutgoingHeader(),
                                    contentEncoding, null, nocache);
                        } else {
                            final byte[] result = o.getBytes(); // this interrupts streaming (bad idea!)
                            HTTPDemon.sendRespondHeader(conProp, out,
                                    httpVersion, 200, null, mimeType, result.length,
                                    targetDate, null, (templatePatterns == null) ? new ResponseHeader() : templatePatterns.getOutgoingHeader(),
                                    contentEncoding, null, nocache);
                            FileUtils.copy(result, out);
                        }
                    }
                } else { // no html

                    int statusCode = 200;
                    int rangeStartOffset = 0;
                    final ResponseHeader header = new ResponseHeader();

                    // adding the accept ranges header
                    header.put(HeaderFramework.ACCEPT_RANGES, "bytes");

                    // reading the files md5 hash if availabe and use it as ETAG of the resource
                    String targetMD5 = null;
                    final File targetMd5File = new File(targetFile + ".md5");
                    try {
                        if (targetMd5File.exists()) {
                            //String description = null;
                            targetMD5 = UTF8.String(FileUtils.read(targetMd5File));
                            final int pos = targetMD5.indexOf('\n');
                            if (pos >= 0) {
                                //description = targetMD5.substring(pos + 1);
                                targetMD5 = targetMD5.substring(0, pos);
                            }

                            // using the checksum as ETAG header
                            header.put(HeaderFramework.ETAG, targetMD5);
                        }
                    } catch (final IOException e) {
                        Log.logException(e);
                    }

                    if (requestHeader.containsKey(HeaderFramework.RANGE)) {
                        final Object ifRange = requestHeader.ifRange();
                        if ((ifRange == null)||
                            (ifRange instanceof Date && targetFile.lastModified() == ((Date)ifRange).getTime()) ||
                            (ifRange instanceof String && ifRange.equals(targetMD5))) {
                            final String rangeHeaderVal = requestHeader.get(HeaderFramework.RANGE).trim();
                            if (rangeHeaderVal.startsWith("bytes=")) {
                                final String rangesVal = rangeHeaderVal.substring("bytes=".length());
                                final String[] ranges = rangesVal.split(",");
                                if ((ranges.length == 1)&&(ranges[0].endsWith("-"))) {
                                    rangeStartOffset = Integer.parseInt(ranges[0].substring(0,ranges[0].length()-1));
                                    statusCode = 206;
                                    header.put(HeaderFramework.CONTENT_RANGE, "bytes " + rangeStartOffset + "-" + (targetFile.length()-1) + "/" + targetFile.length());
                                }
                            }
                        }
                    }

                    // write the file to the client
                    targetDate = new Date(targetFile.lastModified());
                    final long   contentLength    = (zipContent)?-1:targetFile.length()-rangeStartOffset;
                    final String contentEncoding  = (zipContent) ? "gzip" : null;
                    final String transferEncoding = (httpVersion.equals(HeaderFramework.HTTP_VERSION_1_1) && zipContent) ? "chunked" : null;
                    if (!httpVersion.equals(HeaderFramework.HTTP_VERSION_1_1) && zipContent) forceConnectionClose(conProp);

                    HTTPDemon.sendRespondHeader(conProp, out, httpVersion, statusCode, null, mimeType, contentLength, targetDate, null, header, contentEncoding, transferEncoding, nocache);

                    if (!method.equals(HeaderFramework.METHOD_HEAD)) {
                        ChunkedOutputStream chunkedOut = null;
                        GZIPOutputStream zipped = null;
                        OutputStream newOut = out;

                        if (transferEncoding != null) {
                            chunkedOut = new ChunkedOutputStream(newOut);
                            newOut = chunkedOut;
                        }
                        if (contentEncoding != null) {
                            zipped = new GZIPOutputStream(newOut);
                            newOut = zipped;
                        }

                        FileUtils.copyRange(targetFile, newOut, rangeStartOffset);

                        if (zipped != null) {
                            zipped.flush();
                            zipped.finish();
                        }
                        if (chunkedOut != null) {
                            chunkedOut.finish();
                        }
View Full Code Here

      Object encoding = context.getHeaders().getFirst(HttpHeaders.CONTENT_ENCODING);

      if (encoding != null && encoding.toString().equalsIgnoreCase("gzip"))
      {
         OutputStream old = context.getOutputStream();
         GZIPOutputStream gzipOutputStream = new EndableGZIPOutputStream(old);
         context.setOutputStream(gzipOutputStream);
         try
         {
            context.proceed();
         }
         finally
         {
            gzipOutputStream.finish();
            context.setOutputStream(old);
         }
         return;
      }
      else
View Full Code Here

    super();
    closed = false;
    this.response = response;
    this.output = response.getOutputStream();
    baos = new ByteArrayOutputStream();
    gzipstream = new GZIPOutputStream(baos);
  }
View Full Code Here

     * @return the compressed byte array
     * @throws IOException if an excption occurs
     */
  static byte[] compress(byte[] data) throws IOException {
      ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
      GZIPOutputStream out = new GZIPOutputStream(bos);
     
        out.write(data);
        out.close();
        return bos.toByteArray();
    }
View Full Code Here

TOP

Related Classes of java.util.zip.GZIPOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.