01: package pygmy.nntp;
02:
03: import sun.misc.BASE64Encoder;
04: import sun.misc.BASE64Decoder;
05:
06: import java.text.DateFormat;
07: import java.text.SimpleDateFormat;
08: import java.text.ParseException;
09: import java.util.Date;
10: import java.io.IOException;
11:
12: /**
13: * Created by IntelliJ IDEA.
14: * User: Charlie
15: * Date: Oct 15, 2003
16: * Time: 9:59:41 PM
17: * To change this template use Options | File Templates.
18: */
19: public class NntpUtil {
20: private static DateFormat format = new SimpleDateFormat(
21: "EE, dd-MM-yy HH:mm:ss Z");
22: private static BASE64Encoder encoder = new BASE64Encoder();
23: private static BASE64Decoder decoder = new BASE64Decoder();
24:
25: public static String toDateString(Date aDate) {
26: synchronized (format) {
27: return format.format(aDate);
28: }
29: }
30:
31: public static String base64Encode(String messageId) {
32: synchronized (encoder) {
33: return encoder.encode(messageId.getBytes());
34: }
35: }
36:
37: public static byte[] base64Decode(String base64Message)
38: throws IOException {
39: synchronized (decoder) {
40: return decoder.decodeBuffer(base64Message);
41: }
42: }
43:
44: public static Date toDate(String dateString) throws ParseException {
45: synchronized (format) {
46: return format.parse(dateString);
47: }
48: }
49:
50: }
|