View Javadoc

1   /*
2    * Entagged Audio Tag library
3    * Copyright (c) 2003-2005 Raphaël Slinckx <raphael@slinckx.net>
4    * 
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *  
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   * 
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18   */
19  package entagged.audioformats.ape.util;
20  
21  import java.io.UnsupportedEncodingException;
22  import entagged.audioformats.generic.TagField;
23  import entagged.audioformats.generic.TagTextField;
24  
25  
26  public class ApeTagTextField extends ApeTagField implements TagTextField  {
27      
28      private String content;
29  
30      public ApeTagTextField(String id, String content) {
31          super(id, false);
32          this.content = content;
33      }
34      
35      public boolean isEmpty() {
36          return this.content.equals("");
37      }
38      
39      public String toString() {
40          return this.content;
41      }
42      
43      public void copyContent(TagField field) {
44          if(field instanceof ApeTagTextField) {
45              this.content = ((ApeTagTextField)field).getContent();
46          }
47      }
48      
49      public String getContent() {
50          return this.content;
51      }
52  
53      public String getEncoding() {
54          return "UTF-8";
55      }
56      public void setEncoding(String s) {
57          /* Not allowed */
58      }
59  
60      public void setContent(String s) {
61          this.content = s;
62      }
63      
64      public byte[] getRawContent() throws UnsupportedEncodingException {
65          byte[] idBytes = getBytes(getId(), "ISO-8859-1");
66          byte[] contentBytes = getBytes(content, getEncoding());
67  		byte[] buf = new byte[4 + 4 + idBytes.length + 1 + contentBytes.length];
68  		byte[] flags = {0x00,0x00,0x00,0x00};
69  		
70  		int offset = 0;
71  		copy(getSize(contentBytes.length), buf, offset);offset += 4;
72  		copy(flags, buf, offset);                       offset += 4;
73  		copy(idBytes, buf, offset);                     offset += idBytes.length;
74  		buf[offset] = 0;                                offset += 1;
75  		copy(contentBytes, buf, offset);                offset += contentBytes.length;
76  		
77  		return buf;
78      }
79  }