1 // ========================================================================
2 // Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
3 // ------------------------------------------------------------------------
4 // All rights reserved. This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v1.0
6 // and Apache License v2.0 which accompanies this distribution.
7 // The Eclipse Public License is available at
8 // http://www.eclipse.org/legal/epl-v10.html
9 // The Apache License v2.0 is available at
10 // http://www.opensource.org/licenses/apache2.0.php
11 // You may elect to redistribute this code under either of these licenses.
12 // ========================================================================
13
14 package org.eclipse.jetty.io;
15
16 import java.text.DateFormatSymbols;
17 import java.util.Locale;
18
19 import org.eclipse.jetty.util.DateCache;
20
21 public class BufferDateCache extends DateCache
22 {
23 Buffer _buffer;
24 String _last;
25
26 public BufferDateCache()
27 {
28 super();
29 }
30
31 public BufferDateCache(String format, DateFormatSymbols s)
32 {
33 super(format,s);
34 }
35
36 public BufferDateCache(String format, Locale l)
37 {
38 super(format,l);
39 }
40
41 public BufferDateCache(String format)
42 {
43 super(format);
44 }
45
46 public synchronized Buffer formatBuffer(long date)
47 {
48 String d = super.format(date);
49 //noinspection StringEquality
50 if (d==_last)
51 return _buffer;
52 _last=d;
53 _buffer=new ByteArrayBuffer(d);
54
55 return _buffer;
56 }
57 }