KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > emb > MediaSegment


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

6
7 package javax.emb;
8
9 import java.net.URL;
10
11 /**
12  * This class models a portion of a (usually non-embedded) medium that is
13  * optionally followed by a reference to an external media file represented by
14  * a media location URL.
15  *
16  * <p>Splitting up media content into media segments is useful if references
17  * contained have to be updated, for example because one of the children has
18  * moved. In order to handle such a situation it is necessary to disassemble
19  * the media, update the reference, and reassemble it afterwards. MediaFormat
20  * instances provide the operations necessary, and the MediaSegment class
21  * describes the data container for a single segment.
22  *
23  * <p>The value <code>null</code> is a valid value for the childLocation
24  * property and indicates that the segment content is not followed by any
25  * reference, for example because the end of media is reached. The content of
26  * media segments is restricted to a theoretical maximum size of 2GB due to the
27  * Java restriction of byte array size. However this should not impose a
28  * restriction in practice as non-embedded media tends to be fairly small in
29  * size, and embedded media doesn't require segmentation at all.
30  *
31  * <p>Media segments also implement {@link java.io.Serializable} in order to
32  * allow instances to be exchanged over remote boundaries.
33  *
34  * @version <tt>$Revision: 1.4 $</tt>
35  * @author <a HREF="mailto:ricardoarguello@users.sourceforge.net">Ricardo
36  * Argüello</a>
37  */

38 public final class MediaSegment
39 {
40    private byte[] content;
41    private URL childLocation;
42
43    /**
44     * Default constructor for media segments. The content field is initialized
45     * to an empty byte array, and the child location field is initialized to
46     * <code>null</code>.
47     */

48    public MediaSegment()
49    {
50       content = new byte[0];
51       childLocation = null;
52    }
53
54    /**
55     * Returns the content of the media segment as a byte array.
56     *
57     * @return the segment content.
58     */

59    public byte[] getContent()
60    {
61       return content;
62    }
63
64    /**
65     * Returns the media location of a media resource referenced by the
66     * receiver.
67     *
68     * @return the child location.
69     */

70    public URL getChildLocation()
71    {
72       return childLocation;
73    }
74
75    /**
76     * Sets the content of the media segment.
77     *
78     * @param content the segment content.
79     * @throws java.lang.NullPointerException if the value passed is <code>null</code>.
80     */

81    public void setContent(byte[] content)
82    {
83       if (content == null)
84       {
85          throw new NullPointerException();
86       }
87
88       this.content = content;
89    }
90
91    /**
92     * Sets the media location of a media resource referenced by the receiver.
93     * Passing the value <code>null</code> is allowed.
94     *
95     * @param childLocation the child location.
96     */

97    public void setChildLocation(URL childLocation)
98    {
99       this.childLocation = childLocation;
100    }
101 }
Popular Tags