Remove HttpHeaderDateFormat class (#8807)

Motivation:

HttpHeaderDateFormat was replaced with DateFormatter many days ago and now can be easily removed.

Modification:

Remove deprecated class and related test / benchmark

Result:

Less code to maintain
This commit is contained in:
Dmitriy Dumanskiy 2019-01-31 08:22:20 +02:00 committed by Norman Maurer
parent 4b7e5c96b4
commit 67b23ab056
3 changed files with 0 additions and 221 deletions

View File

@ -1,104 +0,0 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project 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 io.netty.handler.codec.http;
import io.netty.util.concurrent.FastThreadLocal;
import io.netty.handler.codec.DateFormatter;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
/**
* This DateFormat decodes 3 formats of {@link Date}, but only encodes the one,
* the first:
* <ul>
* <li>Sun, 06 Nov 1994 08:49:37 GMT: standard specification, the only one with
* valid generation</li>
* <li>Sunday, 06-Nov-94 08:49:37 GMT: obsolete specification</li>
* <li>Sun Nov 6 08:49:37 1994: obsolete specification</li>
* </ul>
* @deprecated Use {@link DateFormatter} instead
*/
@Deprecated
public final class HttpHeaderDateFormat extends SimpleDateFormat {
private static final long serialVersionUID = -925286159755905325L;
private final SimpleDateFormat format1 = new HttpHeaderDateFormatObsolete1();
private final SimpleDateFormat format2 = new HttpHeaderDateFormatObsolete2();
private static final FastThreadLocal<HttpHeaderDateFormat> dateFormatThreadLocal =
new FastThreadLocal<HttpHeaderDateFormat>() {
@Override
protected HttpHeaderDateFormat initialValue() {
return new HttpHeaderDateFormat();
}
};
public static HttpHeaderDateFormat get() {
return dateFormatThreadLocal.get();
}
/**
* Standard date format<p>
* Sun, 06 Nov 1994 08:49:37 GMT -> E, d MMM yyyy HH:mm:ss z
*/
private HttpHeaderDateFormat() {
super("E, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH);
setTimeZone(TimeZone.getTimeZone("GMT"));
}
@Override
public Date parse(String text, ParsePosition pos) {
Date date = super.parse(text, pos);
if (date == null) {
date = format1.parse(text, pos);
}
if (date == null) {
date = format2.parse(text, pos);
}
return date;
}
/**
* First obsolete format<p>
* Sunday, 06-Nov-94 08:49:37 GMT -> E, d-MMM-y HH:mm:ss z
*/
private static final class HttpHeaderDateFormatObsolete1 extends SimpleDateFormat {
private static final long serialVersionUID = -3178072504225114298L;
HttpHeaderDateFormatObsolete1() {
super("E, dd-MMM-yy HH:mm:ss z", Locale.ENGLISH);
setTimeZone(TimeZone.getTimeZone("GMT"));
}
}
/**
* Second obsolete format
* <p>
* Sun Nov 6 08:49:37 1994 -> EEE, MMM d HH:mm:ss yyyy
*/
private static final class HttpHeaderDateFormatObsolete2 extends SimpleDateFormat {
private static final long serialVersionUID = 3010674519968303714L;
HttpHeaderDateFormatObsolete2() {
super("E MMM d HH:mm:ss yyyy", Locale.ENGLISH);
setTimeZone(TimeZone.getTimeZone("GMT"));
}
}
}

View File

@ -1,67 +0,0 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project 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 io.netty.handler.codec.http;
import org.junit.Test;
import java.text.ParseException;
import java.util.Date;
import static org.junit.Assert.*;
public class HttpHeaderDateFormatTest {
/**
* This date is set at "06 Nov 1994 08:49:37 GMT" (same used in example in
* RFC documentation)
* <p>
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html
*/
private static final Date DATE = new Date(784111777000L);
@Test
public void testParse() throws ParseException {
HttpHeaderDateFormat format = HttpHeaderDateFormat.get();
final Date parsedDateWithSingleDigitDay = format.parse("Sun, 6 Nov 1994 08:49:37 GMT");
assertNotNull(parsedDateWithSingleDigitDay);
assertEquals(DATE, parsedDateWithSingleDigitDay);
final Date parsedDateWithDoubleDigitDay = format.parse("Sun, 06 Nov 1994 08:49:37 GMT");
assertNotNull(parsedDateWithDoubleDigitDay);
assertEquals(DATE, parsedDateWithDoubleDigitDay);
final Date parsedDateWithDashSeparatorSingleDigitDay = format.parse("Sunday, 06-Nov-94 08:49:37 GMT");
assertNotNull(parsedDateWithDashSeparatorSingleDigitDay);
assertEquals(DATE, parsedDateWithDashSeparatorSingleDigitDay);
final Date parsedDateWithSingleDoubleDigitDay = format.parse("Sunday, 6-Nov-94 08:49:37 GMT");
assertNotNull(parsedDateWithSingleDoubleDigitDay);
assertEquals(DATE, parsedDateWithSingleDoubleDigitDay);
final Date parsedDateWithoutGMT = format.parse("Sun Nov 6 08:49:37 1994");
assertNotNull(parsedDateWithoutGMT);
assertEquals(DATE, parsedDateWithoutGMT);
}
@Test
public void testFormat() {
HttpHeaderDateFormat format = HttpHeaderDateFormat.get();
final String formatted = format.format(DATE);
assertNotNull(formatted);
assertEquals("Sun, 06 Nov 1994 08:49:37 GMT", formatted);
}
}

View File

@ -1,50 +0,0 @@
/*
* Copyright 2016 The Netty Project
*
* The Netty Project 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 io.netty.handler.codec;
import io.netty.handler.codec.http.HttpHeaderDateFormat;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@OutputTimeUnit(TimeUnit.SECONDS)
public class DateFormatterBenchmark {
private static final String DATE_STRING = "Sun, 27 Nov 2016 19:18:46 GMT";
private static final Date DATE = new Date(784111777000L);
@Benchmark
public Date parseHttpHeaderDateFormatter() {
return DateFormatter.parseHttpDate(DATE_STRING);
}
@Benchmark
public Date parseHttpHeaderDateFormat() throws Exception {
return HttpHeaderDateFormat.get().parse(DATE_STRING);
}
@Benchmark
public String formatHttpHeaderDateFormatter() {
return DateFormatter.format(DATE);
}
@Benchmark
public String formatHttpHeaderDateFormat() throws Exception {
return HttpHeaderDateFormat.get().format(DATE);
}
}