1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.http;
17
18 import io.netty.util.concurrent.FastThreadLocal;
19
20 import java.text.ParsePosition;
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23 import java.util.Locale;
24 import java.util.TimeZone;
25
26
27
28
29
30
31
32
33
34
35
36 public final class HttpHeaderDateFormat extends SimpleDateFormat {
37 private static final long serialVersionUID = -925286159755905325L;
38
39 private final SimpleDateFormat format1 = new HttpHeaderDateFormatObsolete1();
40 private final SimpleDateFormat format2 = new HttpHeaderDateFormatObsolete2();
41
42 private static final FastThreadLocal<HttpHeaderDateFormat> dateFormatThreadLocal =
43 new FastThreadLocal<HttpHeaderDateFormat>() {
44 @Override
45 protected HttpHeaderDateFormat initialValue() {
46 return new HttpHeaderDateFormat();
47 }
48 };
49
50 public static HttpHeaderDateFormat get() {
51 return dateFormatThreadLocal.get();
52 }
53
54
55
56
57
58 private HttpHeaderDateFormat() {
59 super("E, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH);
60 setTimeZone(TimeZone.getTimeZone("GMT"));
61 }
62
63 @Override
64 public Date parse(String text, ParsePosition pos) {
65 Date date = super.parse(text, pos);
66 if (date == null) {
67 date = format1.parse(text, pos);
68 }
69 if (date == null) {
70 date = format2.parse(text, pos);
71 }
72 return date;
73 }
74
75
76
77
78
79 private static final class HttpHeaderDateFormatObsolete1 extends SimpleDateFormat {
80 private static final long serialVersionUID = -3178072504225114298L;
81
82 HttpHeaderDateFormatObsolete1() {
83 super("E, dd-MMM-yy HH:mm:ss z", Locale.ENGLISH);
84 setTimeZone(TimeZone.getTimeZone("GMT"));
85 }
86 }
87
88
89
90
91
92
93 private static final class HttpHeaderDateFormatObsolete2 extends SimpleDateFormat {
94 private static final long serialVersionUID = 3010674519968303714L;
95
96 HttpHeaderDateFormatObsolete2() {
97 super("E MMM d HH:mm:ss yyyy", Locale.ENGLISH);
98 setTimeZone(TimeZone.getTimeZone("GMT"));
99 }
100 }
101 }