Few comments: - the buffer size and deflater are not configurable - since there are no many users of KryoSerializer (wicketstuff-kryo) I guess it is not a problem that the new class is not useful for them and they have to roll their own
On Mon, Feb 20, 2012 at 5:06 PM, <papega...@apache.org> wrote: > Updated Branches: > refs/heads/master ec9c3c7f9 -> 66e5dee52 > > > 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/66e5dee5 > Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/66e5dee5 > Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/66e5dee5 > > Branch: refs/heads/master > Commit: 66e5dee52a014cab24d80f6e3fd30a7d18efaf9e > Parents: ec9c3c7 > Author: Emond Papegaaij <emond.papega...@topicus.nl> > Authored: Mon Feb 20 17:04:32 2012 +0100 > Committer: Emond Papegaaij <papega...@apache.org> > Committed: Mon Feb 20 17:06:21 2012 +0100 > > ---------------------------------------------------------------------- > .../serialize/java/DeflatedJavaSerializer.java | 70 +++++++++++++++ > 1 files changed, 70 insertions(+), 0 deletions(-) > ---------------------------------------------------------------------- > > > http://git-wip-us.apache.org/repos/asf/wicket/blob/66e5dee5/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)); > + } > +} > -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com