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 * Containing genre information and contained in the <code>UserDataBox</code>. 28 * 29 * @see com.coremedia.iso.boxes.UserDataBox 30 */ 31 public class GenreBox extends AbstractFullBox { 32 public static final String TYPE = "gnre"; 33 34 private String language; 35 private String genre; 36 GenreBox()37 public GenreBox() { 38 super(TYPE); 39 } 40 getLanguage()41 public String getLanguage() { 42 return language; 43 } 44 getGenre()45 public String getGenre() { 46 return genre; 47 } 48 setLanguage(String language)49 public void setLanguage(String language) { 50 this.language = language; 51 } 52 setGenre(String genre)53 public void setGenre(String genre) { 54 this.genre = genre; 55 } 56 getContentSize()57 protected long getContentSize() { 58 return 7 + Utf8.utf8StringLengthInBytes(genre); 59 } 60 61 @Override _parseDetails(ByteBuffer content)62 public void _parseDetails(ByteBuffer content) { 63 parseVersionAndFlags(content); 64 language = IsoTypeReader.readIso639(content); 65 genre = IsoTypeReader.readString(content); 66 } 67 68 @Override getContent(ByteBuffer byteBuffer)69 protected void getContent(ByteBuffer byteBuffer) { 70 writeVersionAndFlags(byteBuffer); 71 IsoTypeWriter.writeIso639(byteBuffer, language); 72 byteBuffer.put(Utf8.convert(genre)); 73 byteBuffer.put((byte) 0); 74 } 75 toString()76 public String toString() { 77 return "GenreBox[language=" + getLanguage() + ";genre=" + getGenre() + "]"; 78 } 79 80 } 81