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