KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > media > format > audio > oggvorbis > OggVorbisHeader


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.media.format.audio.oggvorbis;
9
10 import java.io.IOException JavaDoc;
11 import java.io.InputStream JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import javax.emb.MediaException;
16 import javax.emb.MediaHeader;
17
18 /**
19  * Represents an Ogg Vorbis header.
20  *
21  * <p>More info at <a HREF="http://www.vorbis.com/">www.vorbis.com</a> and
22  * <a HREF="http://www.xiph.org/ogg/vorbis/">www.xiph.org/ogg/vorbis</a>.
23  *
24  * @version <tt>$Revision: 1.2 $</tt>
25  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo ArgŁello</a>
26  */

27 public class OggVorbisHeader implements MediaHeader
28 {
29    // Field name keys for fields map
30
private final static String JavaDoc CHANNELS_KEY = "channels";
31    private final static String JavaDoc RATE_KEY = "rate";
32    private final static String JavaDoc BITRATE_KEY = "bitRate";
33    private final static String JavaDoc COMMENTS_KEY = "comments";
34
35    // Map to hold fields in
36
private final Map JavaDoc fieldMap = new HashMap JavaDoc(4);
37
38    /**
39     * Default constructor
40     */

41    public OggVorbisHeader(InputStream JavaDoc content) throws MediaException
42    {
43       try
44       {
45          // Extract metadata
46
VorbisInfo info = new VorbisInfo(content);
47
48          fieldMap.put(CHANNELS_KEY, new Integer JavaDoc(info.getChannels()));
49          fieldMap.put(RATE_KEY, new Long JavaDoc(info.getRate()));
50          fieldMap.put(BITRATE_KEY, new Long JavaDoc(info.getBitrate()));
51          fieldMap.put(COMMENTS_KEY, info.getComments());
52       }
53       catch (IOException JavaDoc e)
54       {
55          throw new MediaException("Error creating VorbisInfo helper object", e);
56       }
57    }
58
59    /**
60     * @see javax.emb.MediaHeader#getFieldNames()
61     */

62    public String JavaDoc[] getFieldNames()
63    {
64       return (String JavaDoc[]) fieldMap.keySet().toArray(new String JavaDoc[0]);
65    }
66
67    /**
68     * @see javax.emb.MediaHeader#getField(java.lang.String)
69     */

70    public Object JavaDoc getField(String JavaDoc fieldName)
71    {
72       return fieldMap.get(fieldName);
73    }
74 }
Popular Tags