diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderDateFormat.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderDateFormat.java deleted file mode 100644 index 45de26df61..0000000000 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderDateFormat.java +++ /dev/null @@ -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: - *
- * 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
- * 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 - *
- * 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")); - } - } -} diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeaderDateFormatTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeaderDateFormatTest.java deleted file mode 100644 index 4f4a6e0fb3..0000000000 --- a/codec-http/src/test/java/io/netty/handler/codec/http/HttpHeaderDateFormatTest.java +++ /dev/null @@ -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) - *
- * 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); - } -} diff --git a/microbench/src/main/java/io/netty/handler/codec/DateFormatterBenchmark.java b/microbench/src/main/java/io/netty/handler/codec/DateFormatterBenchmark.java deleted file mode 100644 index 5d2a11adc5..0000000000 --- a/microbench/src/main/java/io/netty/handler/codec/DateFormatterBenchmark.java +++ /dev/null @@ -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); - } -}