Code cleanup.

This commit is contained in:
Simone Bordet 2017-04-03 22:20:54 +02:00
parent 1d9f9e86c0
commit a994244454
1 changed files with 11 additions and 23 deletions

View File

@ -69,20 +69,11 @@ public class Response implements HttpServletResponse
{
private static final Logger LOG = Log.getLogger(Response.class);
private static final String __COOKIE_DELIM="\",;\\ \t";
private final static String __01Jan1970_COOKIE = DateGenerator.formatCookieDate(0).trim();
private final static int __MIN_BUFFER_SIZE = 1;
private final static HttpField __EXPIRES_01JAN1970 = new PreEncodedHttpField(HttpHeader.EXPIRES,DateGenerator.__01Jan1970);
private static final String __01Jan1970_COOKIE = DateGenerator.formatCookieDate(0).trim();
private static final int __MIN_BUFFER_SIZE = 1;
private static final HttpField __EXPIRES_01JAN1970 = new PreEncodedHttpField(HttpHeader.EXPIRES,DateGenerator.__01Jan1970);
// Cookie building buffer. Reduce garbage for cookie using applications
private static final ThreadLocal<StringBuilder> __cookieBuilder = new ThreadLocal<StringBuilder>()
{
@Override
protected StringBuilder initialValue()
{
return new StringBuilder(128);
}
};
private static final ThreadLocal<StringBuilder> __cookieBuilder = ThreadLocal.withInitial(() -> new StringBuilder(128));
public enum OutputType
{
@ -117,10 +108,9 @@ public class Response implements HttpServletResponse
private ResponseWriter _writer;
private long _contentLength = -1;
private enum EncodingFrom { NOT_SET, INFERRED, SET_LOCALE, SET_CONTENT_TYPE, SET_CHARACTER_ENCODING };
private enum EncodingFrom { NOT_SET, INFERRED, SET_LOCALE, SET_CONTENT_TYPE, SET_CHARACTER_ENCODING }
private static final EnumSet<EncodingFrom> __localeOverride = EnumSet.of(EncodingFrom.NOT_SET,EncodingFrom.INFERRED);
private static final EnumSet<EncodingFrom> __explicitCharset = EnumSet.of(EncodingFrom.SET_LOCALE,EncodingFrom.SET_CHARACTER_ENCODING);
public Response(HttpChannel channel, HttpOutput out)
{
@ -686,7 +676,7 @@ public class Response implements HttpServletResponse
/**
* Sends a response with one of the 300 series redirection codes.
* @param code the redirect status code
* @param location the location to send in <code>Location</code> headers
* @param location the location to send in {@code Location} headers
* @throws IOException if unable to send the redirect
*/
public void sendRedirect(int code, String location) throws IOException
@ -765,7 +755,7 @@ public class Response implements HttpServletResponse
if (HttpHeader.CONTENT_LENGTH == name)
{
if (value == null)
_contentLength = -1l;
_contentLength = -1L;
else
_contentLength = Long.parseLong(value);
}
@ -790,7 +780,7 @@ public class Response implements HttpServletResponse
if (HttpHeader.CONTENT_LENGTH.is(name))
{
if (value == null)
_contentLength = -1l;
_contentLength = -1L;
else
_contentLength = Long.parseLong(value);
}
@ -800,8 +790,7 @@ public class Response implements HttpServletResponse
@Override
public Collection<String> getHeaderNames()
{
final HttpFields fields = _fields;
return fields.getFieldNamesCollection();
return _fields.getFieldNamesCollection();
}
@Override
@ -813,8 +802,7 @@ public class Response implements HttpServletResponse
@Override
public Collection<String> getHeaders(String name)
{
final HttpFields fields = _fields;
Collection<String> i = fields.getValuesList(name);
Collection<String> i = _fields.getValuesList(name);
if (i == null)
return Collections.emptyList();
return i;
@ -1290,7 +1278,7 @@ public class Response implements HttpServletResponse
}
if (preserveCookies)
cookies.forEach(f->_fields.add(f));
cookies.forEach(_fields::add);
else
{
Request request = getHttpChannel().getRequest();