• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.coremedia.iso.boxes;
18 
19 import com.coremedia.iso.IsoTypeReader;
20 import com.coremedia.iso.IsoTypeWriter;
21 import com.coremedia.iso.Utf8;
22 import com.googlecode.mp4parser.AbstractFullBox;
23 
24 import java.nio.ByteBuffer;
25 
26 /**
27  * List of keywords according to 3GPP 26.244.
28  */
29 public class KeywordsBox extends AbstractFullBox {
30     public static final String TYPE = "kywd";
31 
32     private String language;
33     private String[] keywords;
34 
KeywordsBox()35     public KeywordsBox() {
36         super(TYPE);
37     }
38 
getLanguage()39     public String getLanguage() {
40         return language;
41     }
42 
getKeywords()43     public String[] getKeywords() {
44         return keywords;
45     }
46 
setLanguage(String language)47     public void setLanguage(String language) {
48         this.language = language;
49     }
50 
setKeywords(String[] keywords)51     public void setKeywords(String[] keywords) {
52         this.keywords = keywords;
53     }
54 
getContentSize()55     protected long getContentSize() {
56         long contentSize = 7;
57         for (String keyword : keywords) {
58             contentSize += 1 + Utf8.utf8StringLengthInBytes(keyword) + 1;
59         }
60         return contentSize;
61     }
62 
63     @Override
_parseDetails(ByteBuffer content)64     public void _parseDetails(ByteBuffer content) {
65         parseVersionAndFlags(content);
66         language = IsoTypeReader.readIso639(content);
67         int keywordCount = IsoTypeReader.readUInt8(content);
68         keywords = new String[keywordCount];
69         for (int i = 0; i < keywordCount; i++) {
70             IsoTypeReader.readUInt8(content);
71             keywords[i] = IsoTypeReader.readString(content);
72         }
73     }
74 
75     @Override
getContent(ByteBuffer byteBuffer)76     protected void getContent(ByteBuffer byteBuffer) {
77         writeVersionAndFlags(byteBuffer);
78         IsoTypeWriter.writeIso639(byteBuffer, language);
79         IsoTypeWriter.writeUInt8(byteBuffer, keywords.length);
80         for (String keyword : keywords) {
81             IsoTypeWriter.writeUInt8(byteBuffer, Utf8.utf8StringLengthInBytes(keyword) + 1);
82             byteBuffer.put(Utf8.convert(keyword));
83         }
84     }
85 
toString()86     public String toString() {
87         StringBuffer buffer = new StringBuffer();
88         buffer.append("KeywordsBox[language=").append(getLanguage());
89         for (int i = 0; i < keywords.length; i++) {
90             buffer.append(";keyword").append(i).append("=").append(keywords[i]);
91         }
92         buffer.append("]");
93         return buffer.toString();
94     }
95 }
96