Updated Branches: refs/heads/wicket-1.5.x 89c9dd783 -> 2573f2df8
WICKET-4419: added JavaSerializer that deflates on the fly Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/2573f2df Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/2573f2df Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/2573f2df Branch: refs/heads/wicket-1.5.x Commit: 2573f2df8bf9f9ba77ddf373029d558538de6666 Parents: 89c9dd7 Author: Emond Papegaaij <[email protected]> Authored: Mon Feb 20 17:04:32 2012 +0100 Committer: Emond Papegaaij <[email protected]> Committed: Mon Feb 20 17:05:04 2012 +0100 ---------------------------------------------------------------------- .../serialize/java/DeflatedJavaSerializer.java | 70 +++++++++++++++ 1 files changed, 70 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/2573f2df/wicket-core/src/main/java/org/apache/wicket/serialize/java/DeflatedJavaSerializer.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/serialize/java/DeflatedJavaSerializer.java b/wicket-core/src/main/java/org/apache/wicket/serialize/java/DeflatedJavaSerializer.java new file mode 100644 index 0000000..df8416f --- /dev/null +++ b/wicket-core/src/main/java/org/apache/wicket/serialize/java/DeflatedJavaSerializer.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.serialize.java; + +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.util.zip.Deflater; +import java.util.zip.DeflaterOutputStream; +import java.util.zip.Inflater; +import java.util.zip.InflaterInputStream; + +/** + * A {@link JavaSerializer} that deflates the outputstream on the fly, reducing page store size by + * up to a factor 8. Be advised that deflating serialized objects comes at a price of about 2-20ms + * per page request, depending on the size of the page and the cpu power of the machine. + * + * <p> + * To use this serializer, put the following code in your application's init: + * + * <pre> + * getFrameworkSettings().setSerializer(new DeflatedJavaSerializer(getApplicationKey())); + * </pre> + * + * @author papegaaij + */ +public class DeflatedJavaSerializer extends JavaSerializer +{ + private static final int COMPRESS_BUF_SIZE = 4 * 1024; + + /** + * Construct. + * + * @param applicationKey + */ + public DeflatedJavaSerializer(String applicationKey) + { + super(applicationKey); + } + + @Override + protected ObjectOutputStream newObjectOutputStream(OutputStream out) throws IOException + { + return super.newObjectOutputStream(new DeflaterOutputStream(out, new Deflater( + Deflater.BEST_SPEED), COMPRESS_BUF_SIZE)); + } + + @Override + protected ObjectInputStream newObjectInputStream(InputStream in) throws IOException + { + return super.newObjectInputStream(new InflaterInputStream(in, new Inflater(), + COMPRESS_BUF_SIZE)); + } +}
