org.wings.io
Class GZIPCompressingDevice

java.lang.Object
  extended by org.wings.io.GZIPCompressingDevice
All Implemented Interfaces:
Device

public final class GZIPCompressingDevice
extends Object
implements Device

A Device encapsulating an OutputStream, compressing its output. You can use this, if the browser states, that it can handle compressed data; don't forget to set the appropriate header, then (Content-Encoding). Override DeviceFactory and declare the updated factory in web.xml to use other devices.

Example Draft


String mimeType = extInfo.getMimeType();
 // some browsers can handle a gziped stream only for text-files.
 if (mimeType != null && mimeType.startsWith("text/")) {
 String acceptEncoding = req.getHeader("Accept-Encoding");
 int gzipPos;
 if (acceptEncoding != null
 && (gzipPos = acceptEncoding.indexOf("gzip")) >= 0) {
 // some browsers send 'x-gzip', others just 'gzip'. Our
 // response should be the same.
 boolean isXGZip = (gzipPos >= 2
 && acceptEncoding.charAt(gzipPos-1) == '-'
 && acceptEncoding.charAt(gzipPos-2) == 'x');
 response.addHeader("Content-Encoding",
 (isXGZip ? "x-gzip" : "gzip"));
 return new GZIPCompressingDevice(response.getOutputStream());
 }
 }
 return new ServletDevice(response.getOutputStream());
 }
 

Author:
Henner Zeller

Constructor Summary
GZIPCompressingDevice(Device d)
           
GZIPCompressingDevice(OutputStream out)
           
 
Method Summary
 void close()
          close the Device.
 void flush()
          Flush this Device.
 boolean isSizePreserving()
          this returns false, since the compressing device is not size preserving.
 Device print(char c)
          Print a character.
 Device print(char[] c)
          Print a character array.
 Device print(char[] c, int start, int len)
          Print len characters from the specified char array starting at offset off to this Device.
 Device print(int i)
          Print an integer.
 Device print(Object o)
          Print any Object
 Device print(String s)
          Print a String.
 Device write(byte[] b)
          Writes b.length bytes from the specified byte array to this output stream.
 Device write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this Device.
 Device write(int c)
          Writes the specified byte to this data output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GZIPCompressingDevice

public GZIPCompressingDevice(OutputStream out)
                      throws IOException
Throws:
IOException

GZIPCompressingDevice

public GZIPCompressingDevice(Device d)
                      throws IOException
Throws:
IOException
Method Detail

isSizePreserving

public boolean isSizePreserving()
this returns false, since the compressing device is not size preserving. Thats what is all about, right ?

Specified by:
isSizePreserving in interface Device
Returns:
'true', if this device leaves the size of the data going through it, untouched. This is usually true.

flush

public void flush()
           throws IOException
Description copied from interface: Device
Flush this Device.

Specified by:
flush in interface Device
Throws:
IOException

close

public void close()
           throws IOException
Description copied from interface: Device
close the Device.

Specified by:
close in interface Device
Throws:
IOException

print

public Device print(char c)
             throws IOException
Description copied from interface: Device
Print a character.

Specified by:
print in interface Device
Throws:
IOException

print

public Device print(char[] c)
             throws IOException
Description copied from interface: Device
Print a character array.

Specified by:
print in interface Device
Throws:
IOException

print

public Device print(char[] c,
                    int start,
                    int len)
             throws IOException
Description copied from interface: Device
Print len characters from the specified char array starting at offset off to this Device.

Specified by:
print in interface Device
Throws:
IOException

print

public Device print(String s)
             throws IOException
Description copied from interface: Device
Print a String.

Specified by:
print in interface Device
Throws:
IOException

print

public Device print(int i)
             throws IOException
Description copied from interface: Device
Print an integer.

Specified by:
print in interface Device
Throws:
IOException

print

public Device print(Object o)
             throws IOException
Description copied from interface: Device
Print any Object

Specified by:
print in interface Device
Throws:
IOException

write

public Device write(int c)
             throws IOException
Description copied from interface: Device
Writes the specified byte to this data output stream.

Specified by:
write in interface Device
Throws:
IOException

write

public Device write(byte[] b)
             throws IOException
Description copied from interface: Device
Writes b.length bytes from the specified byte array to this output stream.

Specified by:
write in interface Device
Throws:
IOException

write

public Device write(byte[] b,
                    int off,
                    int len)
             throws IOException
Description copied from interface: Device
Writes len bytes from the specified byte array starting at offset off to this Device.

Specified by:
write in interface Device
Throws:
IOException


wingS Swings ;-)