comparison src/org/eclipse/jetty/http/HttpFields.java @ 1019:f126d30e04a4

start replacing BufferCache with StringCache
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 31 Oct 2016 03:33:42 -0600
parents fa6158f29c45
children 6be43ef1eb96
comparison
equal deleted inserted replaced
1018:4dc1e1a18661 1019:f126d30e04a4
57 * <p>This class is not synchronized as it is expected that modifications will only be performed by a 57 * <p>This class is not synchronized as it is expected that modifications will only be performed by a
58 * single thread. 58 * single thread.
59 * 59 *
60 * 60 *
61 */ 61 */
62 public class HttpFields 62 public final class HttpFields
63 { 63 {
64 private static final Logger LOG = LoggerFactory.getLogger(HttpFields.class); 64 private static final Logger LOG = LoggerFactory.getLogger(HttpFields.class);
65 65
66 /* ------------------------------------------------------------ */ 66 private static final String __COOKIE_DELIM="\"\\\n\r\t\f\b%+ ;=";
67 public static final String __COOKIE_DELIM="\"\\\n\r\t\f\b%+ ;="; 67 private static final TimeZone __GMT = TimeZone.getTimeZone("GMT");
68 public static final TimeZone __GMT = TimeZone.getTimeZone("GMT");
69 68
70 /* ------------------------------------------------------------ */
71 private static final String[] DAYS = 69 private static final String[] DAYS =
72 { "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; 70 { "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
73 private static final String[] MONTHS = 71 private static final String[] MONTHS =
74 { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan"}; 72 { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan"};
75 73
76 74
77 /* ------------------------------------------------------------ */
78 private static class DateGenerator 75 private static class DateGenerator
79 { 76 {
80 private final StringBuilder buf = new StringBuilder(32); 77 private final StringBuilder buf = new StringBuilder(32);
81 private final GregorianCalendar gc = new GregorianCalendar(__GMT); 78 private final GregorianCalendar gc = new GregorianCalendar(__GMT);
82 79
159 StringUtil.append2digits(buf, seconds); 156 StringUtil.append2digits(buf, seconds);
160 buf.append(" GMT"); 157 buf.append(" GMT");
161 } 158 }
162 } 159 }
163 160
164 /* ------------------------------------------------------------ */ 161 private static final ThreadLocal<DateGenerator> __dateGenerator = new ThreadLocal<DateGenerator>()
165 private static final ThreadLocal<DateGenerator> __dateGenerator =new ThreadLocal<DateGenerator>()
166 { 162 {
167 @Override 163 @Override
168 protected DateGenerator initialValue() 164 protected DateGenerator initialValue()
169 { 165 {
170 return new DateGenerator(); 166 return new DateGenerator();
173 169
174 /* ------------------------------------------------------------ */ 170 /* ------------------------------------------------------------ */
175 /** 171 /**
176 * Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'" 172 * Format HTTP date "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
177 */ 173 */
178 public static String formatDate(long date) 174 private static String formatDate(long date)
179 { 175 {
180 return __dateGenerator.get().formatDate(date); 176 return __dateGenerator.get().formatDate(date);
181 } 177 }
182 178
183 /* ------------------------------------------------------------ */ 179 /* ------------------------------------------------------------ */
184 /** 180 /**
185 * Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies 181 * Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies
186 */ 182 */
187 public static void formatCookieDate(StringBuilder buf, long date) 183 private static void formatCookieDate(StringBuilder buf, long date)
188 { 184 {
189 __dateGenerator.get().formatCookieDate(buf,date); 185 __dateGenerator.get().formatCookieDate(buf,date);
190 } 186 }
191 187
192 /* ------------------------------------------------------------ */ 188 /* ------------------------------------------------------------ */
193 /** 189 /**
194 * Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies 190 * Format "EEE, dd-MMM-yyyy HH:mm:ss 'GMT'" for cookies
195 */ 191 */
196 public static String formatCookieDate(long date) 192 private static String formatCookieDate(long date)
197 { 193 {
198 StringBuilder buf = new StringBuilder(28); 194 StringBuilder buf = new StringBuilder(28);
199 formatCookieDate(buf, date); 195 formatCookieDate(buf, date);
200 return buf.toString(); 196 return buf.toString();
201 } 197 }
202 198
203 /* ------------------------------------------------------------ */
204 private final static String __dateReceiveFmt[] = 199 private final static String __dateReceiveFmt[] =
205 { 200 {
206 "EEE, dd MMM yyyy HH:mm:ss zzz", 201 "EEE, dd MMM yyyy HH:mm:ss zzz",
207 "EEE, dd-MMM-yy HH:mm:ss", 202 "EEE, dd-MMM-yy HH:mm:ss",
208 "EEE MMM dd HH:mm:ss yyyy", 203 "EEE MMM dd HH:mm:ss yyyy",
214 "MMM dd HH:mm:ss yyyy", "EEE MMM dd HH:mm:ss yyyy zzz", 209 "MMM dd HH:mm:ss yyyy", "EEE MMM dd HH:mm:ss yyyy zzz",
215 "EEE, MMM dd HH:mm:ss yyyy zzz", "EEE, MMM dd HH:mm:ss yyyy", "EEE, dd-MMM-yy HH:mm:ss zzz", 210 "EEE, MMM dd HH:mm:ss yyyy zzz", "EEE, MMM dd HH:mm:ss yyyy", "EEE, dd-MMM-yy HH:mm:ss zzz",
216 "EEE dd-MMM-yy HH:mm:ss zzz", "EEE dd-MMM-yy HH:mm:ss", 211 "EEE dd-MMM-yy HH:mm:ss zzz", "EEE dd-MMM-yy HH:mm:ss",
217 }; 212 };
218 213
219 /* ------------------------------------------------------------ */
220 private static class DateParser 214 private static class DateParser
221 { 215 {
222 final SimpleDateFormat _dateReceive[]= new SimpleDateFormat[__dateReceiveFmt.length]; 216 final SimpleDateFormat _dateReceive[] = new SimpleDateFormat[__dateReceiveFmt.length];
223 217
224 long parse(final String dateVal) 218 long parse(final String dateVal)
225 { 219 {
226 for (int i = 0; i < _dateReceive.length; i++) 220 for (int i = 0; i < _dateReceive.length; i++)
227 { 221 {
261 } 255 }
262 return -1; 256 return -1;
263 } 257 }
264 } 258 }
265 259
266 /* ------------------------------------------------------------ */
267 public static long parseDate(String date)
268 {
269 return __dateParser.get().parse(date);
270 }
271
272 /* ------------------------------------------------------------ */
273 private static final ThreadLocal<DateParser> __dateParser =new ThreadLocal<DateParser>() 260 private static final ThreadLocal<DateParser> __dateParser =new ThreadLocal<DateParser>()
274 { 261 {
275 @Override 262 @Override
276 protected DateParser initialValue() 263 protected DateParser initialValue()
277 { 264 {
278 return new DateParser(); 265 return new DateParser();
279 } 266 }
280 }; 267 };
281 268
282 /* -------------------------------------------------------------- */ 269 private final static String __01Jan1970 = formatDate(0);
283 public final static String __01Jan1970=formatDate(0); 270 private final static Buffer __01Jan1970_BUFFER = new ByteArrayBuffer(__01Jan1970);
284 public final static Buffer __01Jan1970_BUFFER=new ByteArrayBuffer(__01Jan1970); 271 private final static String __01Jan1970_COOKIE = formatCookieDate(0).trim();
285 public final static String __01Jan1970_COOKIE = formatCookieDate(0).trim(); 272
286 273
287 /* -------------------------------------------------------------- */ 274
275
276
277
288 private final ArrayList<Field> _fields = new ArrayList<Field>(20); 278 private final ArrayList<Field> _fields = new ArrayList<Field>(20);
289 private final HashMap<Buffer,Field> _names = new HashMap<Buffer,Field>(32); 279 private final HashMap<Buffer,Field> _names = new HashMap<Buffer,Field>(32);
290 280
291 /* ------------------------------------------------------------ */ 281 /* ------------------------------------------------------------ */
292 /** 282 /**
334 */ 324 */
335 public Collection<String> getFieldNamesCollection() 325 public Collection<String> getFieldNamesCollection()
336 { 326 {
337 final List<String> list = new ArrayList<String>(_fields.size()); 327 final List<String> list = new ArrayList<String>(_fields.size());
338 328
339 for (Field f : _fields) 329 for (Field f : _fields)
340 { 330 {
341 if (f!=null) 331 if (f!=null)
342 list.add(BufferUtil.to8859_1_String(f._name)); 332 list.add(BufferUtil.to8859_1_String(f._name));
343 } 333 }
344 return list; 334 return list;
345 } 335 }
346 336
347 /* -------------------------------------------------------------- */ 337 /* -------------------------------------------------------------- */
348 /** 338 /**
349 * Get enumeration of header _names. Returns an enumeration of strings representing the header 339 * Get enumeration of header _names. Returns an enumeration of strings representing the header