/*
 * 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));
	}
}

@@ -2097,65 +2097,330 @@
 ut, 
-new Deflater(%0A%09%09%09Deflater.BEST_SPEED), COMPRESS_BUF_SIZE)
+createDeflater(),%0A%09%09%09COMPRESS_BUF_SIZE));%0A%09%7D%0A%0A%09/**%0A%09 * Creates the %7B@code Deflater%7D. Override this method to customize the deflater, for example to%0A%09 * change the compression level and/or strategy.%0A%09 * %0A%09 * @return the %7B@code Deflater%7D%0A%09 */%0A%09protected Deflater createDeflater()%0A%09%7B%0A%09%09return new Deflater(Deflater.BEST_SPEED
 );%0A%09

make the deflater configurable