383304 PrintWriter error flag not recycled

This commit is contained in:
Jan Bartel 2012-07-19 15:32:33 +10:00
parent e274379a7f
commit 999f66b6a8
3 changed files with 53 additions and 3 deletions

View File

@ -0,0 +1,48 @@
// ========================================================================
// Copyright (c) 2012-2012 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.io;
import java.io.PrintWriter;
import java.io.Writer;
/* ------------------------------------------------------------ */
/**
* ClearablePrintWriter
*
* Small class to make clearError method callable publically. Used for recycling the print writer on the response object.
*/
public abstract class ClearablePrintWriter extends PrintWriter
{
/* ------------------------------------------------------------ */
public ClearablePrintWriter(Writer writer, boolean autoFlush)
{
super(writer);
}
/* ------------------------------------------------------------ */
public ClearablePrintWriter(Writer writer)
{
super(writer);
}
/* ------------------------------------------------------------ */
public void clearError ()
{
super.clearError();
}
}

View File

@ -30,7 +30,7 @@ import org.eclipse.jetty.util.log.Logger;
* {@link java.io.IOException} thrown by the underlying implementation of
* {@link java.io.Writer} as {@link RuntimeIOException} instances.
*/
public class UncheckedPrintWriter extends PrintWriter
public class UncheckedPrintWriter extends ClearablePrintWriter
{
private static final Logger LOG = Log.getLogger(UncheckedPrintWriter.class);

View File

@ -41,6 +41,7 @@ import org.eclipse.jetty.io.AbstractConnection;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.BufferCache.CachedBuffer;
import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.ClearablePrintWriter;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException;
@ -361,7 +362,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection
if (_server.isUncheckedPrintWriter())
_printWriter=new UncheckedPrintWriter(_writer);
else
_printWriter = new PrintWriter(_writer)
_printWriter = new ClearablePrintWriter(_writer)
{
public void close()
{
@ -378,7 +379,6 @@ public abstract class AbstractHttpConnection extends AbstractConnection
}
}
};
}
_writer.setCharacterEncoding(encoding);
return _printWriter;
@ -402,6 +402,8 @@ public abstract class AbstractHttpConnection extends AbstractConnection
_responseFields.clear();
_response.recycle();
_uri.clear();
if (_printWriter != null && (_printWriter instanceof ClearablePrintWriter))
((ClearablePrintWriter)_printWriter).clearError();
}
/* ------------------------------------------------------------ */