|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.wings.io.GZIPCompressingDevice
public final class GZIPCompressingDevice
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());
}
| 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 |
|---|
public GZIPCompressingDevice(OutputStream out)
throws IOException
IOException
public GZIPCompressingDevice(Device d)
throws IOException
IOException| Method Detail |
|---|
public boolean isSizePreserving()
isSizePreserving in interface Device
public void flush()
throws IOException
Device
flush in interface DeviceIOException
public void close()
throws IOException
Device
close in interface DeviceIOException
public Device print(char c)
throws IOException
Device
print in interface DeviceIOException
public Device print(char[] c)
throws IOException
Device
print in interface DeviceIOException
public Device print(char[] c,
int start,
int len)
throws IOException
Device
print in interface DeviceIOException
public Device print(String s)
throws IOException
Device
print in interface DeviceIOException
public Device print(int i)
throws IOException
Device
print in interface DeviceIOException
public Device print(Object o)
throws IOException
Device
print in interface DeviceIOException
public Device write(int c)
throws IOException
Device
write in interface DeviceIOException
public Device write(byte[] b)
throws IOException
Device
write in interface DeviceIOException
public Device write(byte[] b,
int off,
int len)
throws IOException
Device
write in interface DeviceIOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||