1 /* Copyright (C) 2000 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
14 public class MimeTypes
16 private static Hashtable mime_types
;
18 public static void fillFromFile (Hashtable table
, String fname
)
21 LineNumberReader reader
=
22 new LineNumberReader (new FileReader (fname
));
24 while (reader
.ready ())
26 StringTokenizer tokenizer
=
27 new StringTokenizer (reader
.readLine ());
31 String t
= tokenizer
.nextToken ();
33 if (! t
.startsWith ("#"))
37 // Read the next extension
38 String e
= tokenizer
.nextToken ();
39 if ((e
!= null) && (! e
.startsWith ("#")))
45 } catch (NoSuchElementException ex
) {
51 // This is the primary interface to this class.
52 public static String
getMimeTypeFromExtension (String extension
)
54 if (mime_types
== null)
56 mime_types
= new Hashtable ();
58 // First populate the hash table with the default mime type
60 int i
= DefaultMimeTypes
.types
.length
;
63 mime_types
.put (DefaultMimeTypes
.types
[i
- 2],
64 DefaultMimeTypes
.types
[i
- 1]);
68 // Now read mime types from /etc/mime.types if it exists.
69 // This should override the default values.
71 fillFromFile (mime_types
, "/etc/mime.types");
72 } catch (IOException ex
) {
76 // Now read mime types from ~/.mime.types.
77 // FIXME: We can't currently parse this file.
80 String type
= (String
) mime_types
.get (extension
);
82 return ("application/octet-stream");