filter应用 (四)

2014-11-24 09:49:26 · 作者: · 浏览: 3
] gzip(byte[] data) {
ByteArrayOutputStream byteOutput = new
ByteArrayOutputStream(10240);
GZIPOutputStream output = null;
try {
output = new GZIPOutputStream(byteOutput);
output.write(data);
} catch (IOException e) {
throw new RuntimeException("G-Zip failed.", e);
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
}
}
}
return byteOutput.toByteArray();
}
}
public final class GZipUtil {
/** * Do a gzip operation. */
public static byte[] gzip(byte[] data) {
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(10240);
GZIPOutputStream output = null;
try {
output = new GZIPOutputStream(byteOutput);
output.write(data);
} catch (IOException e) {
throw new RuntimeException("G-Zip failed.", e);
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
}
}
}
return byteOutput.toByteArray();
}
}

(4).在web.xml中配置 GZipFilter

Xml代码

GZipFilter
com.logcd.filter.GZipFilter


GZipFilter
*.html