1/*
2 * Copyright 2008 CoreMedia AG, Hamburg
3 *
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.coremedia.iso.boxes;
18
19
20import com.coremedia.iso.IsoTypeReader;
21import com.coremedia.iso.IsoTypeWriter;
22import com.coremedia.iso.Utf8;
23import com.googlecode.mp4parser.AbstractFullBox;
24
25import java.nio.ByteBuffer;
26
27/**
28 * The copyright box contains a copyright declaration which applies to the entire presentation, when contained
29 * within the MovieBox, or, when contained in a track, to that entire track. There may be multple boxes using
30 * different language codes.
31 *
32 * @see MovieBox
33 * @see TrackBox
34 */
35public class CopyrightBox extends AbstractFullBox {
36    public static final String TYPE = "cprt";
37
38    private String language;
39    private String copyright;
40
41    public CopyrightBox() {
42        super(TYPE);
43    }
44
45    public String getLanguage() {
46        return language;
47    }
48
49    public String getCopyright() {
50        return copyright;
51    }
52
53    public void setLanguage(String language) {
54        this.language = language;
55    }
56
57    public void setCopyright(String copyright) {
58        this.copyright = copyright;
59    }
60
61    protected long getContentSize() {
62        return 7 + Utf8.utf8StringLengthInBytes(copyright);
63    }
64
65    @Override
66    public void _parseDetails(ByteBuffer content) {
67        parseVersionAndFlags(content);
68        language = IsoTypeReader.readIso639(content);
69        copyright = IsoTypeReader.readString(content);
70    }
71
72    @Override
73    protected void getContent(ByteBuffer byteBuffer) {
74        writeVersionAndFlags(byteBuffer);
75        IsoTypeWriter.writeIso639(byteBuffer, language);
76        byteBuffer.put(Utf8.convert(copyright));
77        byteBuffer.put((byte) 0);
78    }
79
80    public String toString() {
81        return "CopyrightBox[language=" + getLanguage() + ";copyright=" + getCopyright() + "]";
82    }
83
84
85
86}
87