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